我的启动活动扩展了ListActivity,并使用了一个包含listview和底部按钮的布局。当我尝试将onclicklistener设置为按钮时,应用程序现在在启动时崩溃。这是我的日志:
04-18 13:03:09.667: ERROR/AndroidRuntime(4388): FATAL EXCEPTION: main
04-18 13:03:09.667: ERROR/AndroidRuntime(4388): java.lang.RuntimeException: 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
答案 0 :(得分:2)
你正在尝试将一些东西作为一个ImageButton投射,这可能是CheckListDemoActivity第30行的一个按钮(反之亦然)。
答案 1 :(得分:1)
问题在于:
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)
com.me.CheckListDemoActivity
中的第30行是什么?