这是来自 logcat:
09-23 17:48:00.288: E/AndroidRuntime(13056): FATAL EXCEPTION: main
09-23 17:48:00.288: E/AndroidRuntime(13056): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mybasicinteractivegraph/com.example.mybasicinteractivegraph.MainActivity}: java.lang.ClassCastException: android.widget.Button cannot be cast to android.widget.SeekBar
09-23 17:48:00.288: E/AndroidRuntime(13056): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
09-23 17:48:00.288: E/AndroidRuntime(13056): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
09-23 17:48:00.288: E/AndroidRuntime(13056): at android.app.ActivityThread.access$600(ActivityThread.java:141)
09-23 17:48:00.288: E/AndroidRuntime(13056): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
09-23 17:48:00.288: E/AndroidRuntime(13056): at android.os.Handler.dispatchMessage(Handler.java:99)
09-23 17:48:00.288: E/AndroidRuntime(13056): at android.os.Looper.loop(Looper.java:137)
09-23 17:48:00.288: E/AndroidRuntime(13056): at android.app.ActivityThread.main(ActivityThread.java:5103)
09-23 17:48:00.288: E/AndroidRuntime(13056): at java.lang.reflect.Method.invokeNative(Native Method)
09-23 17:48:00.288: E/AndroidRuntime(13056): at java.lang.reflect.Method.invoke(Method.java:525)
09-23 17:48:00.288: E/AndroidRuntime(13056): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
09-23 17:48:00.288: E/AndroidRuntime(13056): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-23 17:48:00.288: E/AndroidRuntime(13056): at dalvik.system.NativeStart.main(Native Method)
09-23 17:48:00.288: E/AndroidRuntime(13056): Caused by: java.lang.ClassCastException: android.widget.Button cannot be cast to android.widget.SeekBar
09-23 17:48:00.288: E/AndroidRuntime(13056): at com.example.mybasicinteractivegraph.MainActivity.onCreate(MainActivity.java:49)
09-23 17:48:00.288: E/AndroidRuntime(13056): at android.app.Activity.performCreate(Activity.java:5133)
09-23 17:48:00.288: E/AndroidRuntime(13056): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
09-23 17:48:00.288: E/AndroidRuntime(13056): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
09-23 17:48:00.288: E/AndroidRuntime(13056): ... 11 more
我只发布了从 logcat 中以红色编码的那些。我不知道为什么或如何发生这种情况。最糟糕的是,该程序正在编译并且运行良好,但后来我在 GUI 版本上玩了一会儿activity_main.xml
,突然程序开始崩溃。我放在 onCreate() 开头的Log.d()
代码似乎在 logcat 中显示了它们的错误消息,所以我知道程序至少运行到那个时候。但是为什么之后就崩溃了?这个 logcat 错误是什么意思?