2012-11-14 71 views
0

我試圖從數據庫中檢索特定數據,如自定義廣告,用戶名,日期等。所以遵循這個Need a simple tutorial for android/webservice work?的代碼。我走錯了一些地方任何一個可以幫助我是新來的android.Getting以下錯誤從數據庫中檢索數據

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

請張貼您的代碼。 –

+0

您是否在清單中籤署FetchList活動? – Rasel

+0

一想,這篇文章看起來像這樣一個:http://stackoverflow.com/questions/4688277/java-lang-runtimeexception-unable-to-instantiate-activity-componentinfo –

回答

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的輸出是什麼。

+0

公共類FetchList延伸的AsyncTask <空隙,空隙字節> { \t保護字節doInBackground1(空隙...爲arg0){// 這是在第一步驟中 響應RES解釋=新的響應( 「URL」); String response = res.getResponse(); XMLParser xml = new XMLParser(response); ArrayList itemList = xml.getItemList(); return xml.parse(); } \t @覆蓋 \t保護字節doInBackground(空隙...爲arg0){ \t \t // TODO自動生成方法存根 \t \t返回NULL; \t} } 這是FetchList類,當我運行應用程序其顯示力關閉 – SRY

+0

爲什麼你有2個同名的方法? 在代碼中刪除第二個'doInBackGround()'實例,並在該方法的第一個實例上面添加@ @ Override'簽名。 – varevarao

+0

如果我這樣做,我收到錯誤 – SRY