Android程序没有报错,怎么总是弹出“很抱歉,‘XXXX’已停止运行

时间:2022-03-18 14:46:44
06-14 09:00:26.775: D/dalvikvm(1894): Late-enabling CheckJNI
06-14 09:00:27.787: D/AndroidRuntime(1894): Shutting down VM
06-14 09:00:27.787: W/dalvikvm(1894): threadid=1: thread exiting with uncaught exception (group=0x94ce0b20)
06-14 09:00:27.827: E/AndroidRuntime(1894): FATAL EXCEPTION: main
06-14 09:00:27.827: E/AndroidRuntime(1894): Process: com.example.mobilebutler, PID: 1894
06-14 09:00:27.827: E/AndroidRuntime(1894): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mobilebutler/com.example.mobilebutler.MainActivity}: java.lang.ClassCastException: android.widget.ImageView cannot be cast to android.widget.Button
06-14 09:00:27.827: E/AndroidRuntime(1894):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2219)
06-14 09:00:27.827: E/AndroidRuntime(1894):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2269)
06-14 09:00:27.827: E/AndroidRuntime(1894):  at android.app.ActivityThread.access$800(ActivityThread.java:135)
06-14 09:00:27.827: E/AndroidRuntime(1894):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
06-14 09:00:27.827: E/AndroidRuntime(1894):  at android.os.Handler.dispatchMessage(Handler.java:102)
06-14 09:00:27.827: E/AndroidRuntime(1894):  at android.os.Looper.loop(Looper.java:136)
06-14 09:00:27.827: E/AndroidRuntime(1894):  at android.app.ActivityThread.main(ActivityThread.java:5045)
06-14 09:00:27.827: E/AndroidRuntime(1894):  at java.lang.reflect.Method.invokeNative(Native Method)
06-14 09:00:27.827: E/AndroidRuntime(1894):  at java.lang.reflect.Method.invoke(Method.java:515)
06-14 09:00:27.827: E/AndroidRuntime(1894):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
06-14 09:00:27.827: E/AndroidRuntime(1894):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
06-14 09:00:27.827: E/AndroidRuntime(1894):  at dalvik.system.NativeStart.main(Native Method)
06-14 09:00:27.827: E/AndroidRuntime(1894): Caused by: java.lang.ClassCastException: android.widget.ImageView cannot be cast to android.widget.Button
06-14 09:00:27.827: E/AndroidRuntime(1894):  at com.example.mobilebutler.MainActivity.onCreate(MainActivity.java:17)
06-14 09:00:27.827: E/AndroidRuntime(1894):  at android.app.Activity.performCreate(Activity.java:5231)
06-14 09:00:27.827: E/AndroidRuntime(1894):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
06-14 09:00:27.827: E/AndroidRuntime(1894):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2163)
06-14 09:00:27.827: E/AndroidRuntime(1894):  ... 11 more


这是locat代码

2 个解决方案

#1


遇到了同样的问题。。。

#2


Caused by: java.lang.ClassCastException: android.widget.ImageView cannot be cast to android.widget.Button

异常很明显啊~ 你findViewById返回的应该是个ImageView~  你用Button去接收的~ 类型转换错误~ 检查一下~

#1


遇到了同样的问题。。。

#2


Caused by: java.lang.ClassCastException: android.widget.ImageView cannot be cast to android.widget.Button

异常很明显啊~ 你findViewById返回的应该是个ImageView~  你用Button去接收的~ 类型转换错误~ 检查一下~