2012-02-12 62 views
1

我有一點麻煩。我在這方面是全新的。我試圖讓我的應用程序以啓動屏幕開始,然後繼續進行新的活動,但我的應用程序保持強制關閉的異常情況:main。這是logcat致命例外:主

02-12 02:56:32.989: D/AndroidRuntime(1487): Shutting down VM 
02-12 02:56:32.989: W/dalvikvm(1487): threadid=1: thread exiting with uncaught exception (group=0x4001e560) 
02-12 02:56:33.009: E/AndroidRuntime(1487): FATAL EXCEPTION: main 
02-12 02:56:33.009: E/AndroidRuntime(1487): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.madonk.LAFEST/com.madonk.LAFEST.MAIN}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list' 
02-12 02:56:33.009: E/AndroidRuntime(1487):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1702) 
02-12 02:56:33.009: E/AndroidRuntime(1487):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1722) 
02-12 02:56:33.009: E/AndroidRuntime(1487):  at android.app.ActivityThread.access$1500(ActivityThread.java:124) 
02-12 02:56:33.009: E/AndroidRuntime(1487):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:974) 
02-12 02:56:33.009: E/AndroidRuntime(1487):  at android.os.Handler.dispatchMessage(Handler.java:99) 
02-12 02:56:33.009: E/AndroidRuntime(1487):  at android.os.Looper.loop(Looper.java:130) 
02-12 02:56:33.009: E/AndroidRuntime(1487):  at android.app.ActivityThread.main(ActivityThread.java:3821) 
02-12 02:56:33.009: E/AndroidRuntime(1487):  at java.lang.reflect.Method.invokeNative(Native Method) 
02-12 02:56:33.009: E/AndroidRuntime(1487):  at java.lang.reflect.Method.invoke(Method.java:507) 
02-12 02:56:33.009: E/AndroidRuntime(1487):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 
02-12 02:56:33.009: E/AndroidRuntime(1487):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 
02-12 02:56:33.009: E/AndroidRuntime(1487):  at dalvik.system.NativeStart.main(Native Method) 
02-12 02:56:33.009: E/AndroidRuntime(1487): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list' 
02-12 02:56:33.009: E/AndroidRuntime(1487):  at android.app.ListActivity.onContentChanged(ListActivity.java:243) 
02-12 02:56:33.009: E/AndroidRuntime(1487):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256) 
02-12 02:56:33.009: E/AndroidRuntime(1487):  at android.app.Activity.setContentView(Activity.java:1716) 
02-12 02:56:33.009: E/AndroidRuntime(1487):  at com.madonk.LAFEST.MAIN.onCreate(MAIN.java:17) 
02-12 02:56:33.009: E/AndroidRuntime(1487):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 
02-12 02:56:33.009: E/AndroidRuntime(1487):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1666) 
02-12 02:56:33.009: E/AndroidRuntime(1487):  ... 11 more 

如果有什麼人可以做的幫助,我將不勝感激。

+0

你能張貼您的來源?所有的控制檯告訴我,有一個ListView的問題 – Flynn 2012-02-12 08:10:01

回答

1

您的活動可能延伸ListActivity也正因爲如此在包含您的活動)(您setContentView(R.layout.name_of_layout設置的一個)的佈局你xml文件,你必須有一個ListView元素與ID:

<ListView android:id="@android:id/list" 
//other attributes 
> 
+0

這將無法正常工作,如果他只是刪除setContentView? – 2012-02-12 08:19:07

+1

@ShashankKadne是的,因爲ListView是ListActivity的默認佈局,所以如果你想要的只是一個列表,就不需要setContentView,但他可能設置了內容視圖來定製佈局,在這種情況下他必須有ID爲'@android:id/list'的'ListView'元素。 – Luksprog 2012-02-12 08:22:52

+0

太棒了,謝謝。現在我正在與Crisco一起做飯! – Madonk 2012-02-12 08:25:10