Stopped unexpectedly error when adding startactivity(intent)
My launch activity extends ListActivity and uses a layout that has a listview and a button on the bottom. When I tried setting an onclicklistener to the button, the app now crashes on startup. Here's my log:
04-18 13:03:09.667: ERROR/AndroidRuntime(4388): FATAL EXCEPTION: main
04-18 13:03:09.667: ERROR/AndroidRuntime(4388): java.lang.Runtim开发者_Python百科eException: Unable to start activity ComponentInfo{com.me/com.me.CheckListDemoActivity}: java.lang.ClassCastException: android.widget.ImageButton
04-18 13:03:09.667: ERROR/AndroidRuntime(4388): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
04-18 13:03:09.667: ERROR/AndroidRuntime(4388): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
04-18 13:03:09.667: ERROR/AndroidRuntime(4388): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-18 13:03:09.667: ERROR/AndroidRuntime(4388): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-18 13:03:09.667: ERROR/AndroidRuntime(4388): at android.os.Handler.dispatchMessage(Handler.java:99)
04-18 13:03:09.667: ERROR/AndroidRuntime(4388): at android.os.Looper.loop(Looper.java:123)
04-18 13:03:09.667: ERROR/AndroidRuntime(4388): at android.app.ActivityThread.main(ActivityThread.java:4627)
04-18 13:03:09.667: ERROR/AndroidRuntime(4388): at java.lang.reflect.Method.invokeNative(Native Method)
04-18 13:03:09.667: ERROR/AndroidRuntime(4388): at java.lang.reflect.Method.invoke(Method.java:521)
04-18 13:03:09.667: ERROR/AndroidRuntime(4388): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
04-18 13:03:09.667: ERROR/AndroidRuntime(4388): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
04-18 13:03:09.667: ERROR/AndroidRuntime(4388): at dalvik.system.NativeStart.main(Native Method)
04-18 13:03:09.667: ERROR/AndroidRuntime(4388): Caused by: java.lang.ClassCastException: android.widget.ImageButton
04-18 13:03:09.667: ERROR/AndroidRuntime(4388): at com.me.CheckListDemoActivity.onCreate(CheckListDemoActivity.java:31)
04-18 13:03:09.667: ERROR/AndroidRuntime(4388): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-18 13:03:09.667: ERROR/AndroidRuntime(4388): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
04-18 13:03:09.667: ERROR/AndroidRuntime(4388): ... 11 more
04-18 13:05:42.589: ERROR/AndroidRuntime(4436): FATAL EXCEPTION: main
04-18 13:05:42.589: ERROR/AndroidRuntime(4436): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.me.CheckListDemoActivity}: java.lang.ClassCastException: android.widget.ImageButton
04-18 13:05:42.589: ERROR/AndroidRuntime(4436): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
04-18 13:05:42.589: ERROR/AndroidRuntime(4436): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
04-18 13:05:42.589: ERROR/AndroidRuntime(4436): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-18 13:05:42.589: ERROR/AndroidRuntime(4436): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-18 13:05:42.589: ERROR/AndroidRuntime(4436): at android.os.Handler.dispatchMessage(Handler.java:99)
04-18 13:05:42.589: ERROR/AndroidRuntime(4436): at android.os.Looper.loop(Looper.java:123)
04-18 13:05:42.589: ERROR/AndroidRuntime(4436): at android.app.ActivityThread.main(ActivityThread.java:4627)
04-18 13:05:42.589: ERROR/AndroidRuntime(4436): at java.lang.reflect.Method.invokeNative(Native Method)
04-18 13:05:42.589: ERROR/AndroidRuntime(4436): at java.lang.reflect.Method.invoke(Method.java:521)
04-18 13:05:42.589: ERROR/AndroidRuntime(4436): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
04-18 13:05:42.589: ERROR/AndroidRuntime(4436): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
04-18 13:05:42.589: ERROR/AndroidRuntime(4436): at dalvik.system.NativeStart.main(Native Method)
04-18 13:05:42.589: ERROR/AndroidRuntime(4436): Caused by: java.lang.ClassCastException: android.widget.ImageButton
04-18 13:05:42.589: ERROR/AndroidRuntime(4436): at com.me.CheckListDemoActivity.onCreate(CheckListDemoActivity.java:30)
04-18 13:05:42.589: ERROR/AndroidRuntime(4436): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-18 13:05:42.589: ERROR/AndroidRuntime(4436): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
04-18 13:05:42.589: ERROR/AndroidRuntime(4436): ... 11 more
You are trying to cast something as an ImageButton which is probably a button (or vice versa) on line 30 in CheckListDemoActivity.
The problem is here:
04-18 13:05:42.589: ERROR/AndroidRuntime(4436): Caused by: java.lang.ClassCastException: android.widget.ImageButton
04-18 13:05:42.589: ERROR/AndroidRuntime(4436): at com.me.CheckListDemoActivity.onCreate(CheckListDemoActivity.java:30)
What is line 30 in com.me.CheckListDemoActivity
?
精彩评论