我正在尝试从数据库中检索自定义广告,用户名,日期等特定数据。所以遵循这个Need a simple tutorial for android/webservice work?的代码。我出错了一些可以帮助的人,因为我是android的新手。获取以下错误
11-13 21:57:14.720: E/AndroidRuntime(399): FATAL EXCEPTION: main
11-13 21:57:14.720: E/AndroidRuntime(399): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.response/com.response.FetchList}: java.lang.ClassCastException: com.response.FetchList
11-13 21:57:14.720: E/AndroidRuntime(399): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
11-13 21:57:14.720: E/AndroidRuntime(399): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
11-13 21:57:14.720: E/AndroidRuntime(399): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
11-13 21:57:14.720: E/AndroidRuntime(399): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
11-13 21:57:14.720: E/AndroidRuntime(399): at android.os.Handler.dispatchMessage(Handler.java:99)
11-13 21:57:14.720: E/AndroidRuntime(399): at android.os.Looper.loop(Looper.java:123)
11-13 21:57:14.720: E/AndroidRuntime(399): at android.app.ActivityThread.main(ActivityThread.java:4627)
11-13 21:57:14.720: E/AndroidRuntime(399): at java.lang.reflect.Method.invokeNative(Native Method)
11-13 21:57:14.720: E/AndroidRuntime(399): at java.lang.reflect.Method.invoke(Method.java:521)
11-13 21:57:14.720: E/AndroidRuntime(399): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-13 21:57:14.720: E/AndroidRuntime(399): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-13 21:57:14.720: E/AndroidRuntime(399): at dalvik.system.NativeStart.main(Native Method)
11-13 21:57:14.720: E/AndroidRuntime(399): Caused by: java.lang.ClassCastException: com.response.FetchList
11-13 21:57:14.720: E/AndroidRuntime(399): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
11-13 21:57:14.720: E/AndroidRuntime(399): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
修改 - 的manifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.response"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".Response"
android:label="@string/title_activity_response" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="android.support.v4.app.FragmentActivity" />
</activity>
<activity
android:name=".XMLParser"
android:label="@string/title_activity_response" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".FetchList"
android:label="@string/title_activity_response" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
答案 0 :(得分:1)
如果您完全按原样从该链接获取代码,那么您可能会在该行遇到该错误,
public class FetchList extends asyncTask<Void,Void,Byte>{
doinbackground{
实际上是
public class FetchList extends asyncTask<Void, Void, Byte> {
@Override
protected Byte doInBackground (Void... voids){
...
}
}
编辑:根据评论中的代码
public class FetchList extends AsyncTask<Void,Void,Byte>{
@Override
protected Byte doInBackground1(Void... arg0){
// this was explained in first step
Response res = new Response("url");
String response = res.getResponse();
XMLParser xml = new XMLParser(response);
ArrayList<XMLParser> itemList = xml.getItemList();
return xml.parse();
}
}
在这种情况下,让我知道Logcat输出是什么。