我在開發應用程序時遇到了運行時異常。這是我的LogCat。錯誤/ AndroidRuntime(516):java.lang.RuntimeException:java.lang.ClassCastException:android.widget.TextView
11-06 12:56:09.977: INFO/ActivityManager(59): Starting activity: Intent { cmp=balu.android/.CommonNames }
11-06 12:56:10.096: INFO/CommonNameTable(516): OPening DataBase Connection....
11-06 12:56:10.156: INFO/global(516): Default buffer size used in BufferedReader constructor. It would be better to be explicit if an 8k-char buffer is required.
11-06 12:56:10.156: INFO/CommonNameTable(516): Inserting record...
11-06 12:56:10.306: INFO/CommonNameTable(516): Inserting record...
11-06 12:56:10.428: INFO/CommonNameTable(516): Inserting record...
11-06 12:56:10.546: INFO/CommonNameTable(516): OPening DataBase Connection....
11-06 12:56:10.576: DEBUG/AndroidRuntime(516): Shutting down VM
11-06 12:56:10.576: WARN/dalvikvm(516): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
11-06 12:56:10.596: ERROR/AndroidRuntime(516): FATAL EXCEPTION: main
11-06 12:56:10.596: ERROR/AndroidRuntime(516): java.lang.RuntimeException: Unable to start activity ComponentInfo{balu.android/balu.android.CommonNames}: java.lang.ClassCastException: android.widget.TextView
11-06 12:56:10.596: ERROR/AndroidRuntime(516): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
11-06 12:56:10.596: ERROR/AndroidRuntime(516): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
11-06 12:56:10.596: ERROR/AndroidRuntime(516): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
11-06 12:56:10.596: ERROR/AndroidRuntime(516): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
11-06 12:56:10.596: ERROR/AndroidRuntime(516): at android.os.Handler.dispatchMessage(Handler.java:99)
11-06 12:56:10.596: ERROR/AndroidRuntime(516): at android.os.Looper.loop(Looper.java:123)
11-06 12:56:10.596: ERROR/AndroidRuntime(516): at android.app.ActivityThread.main(ActivityThread.java:4627)
11-06 12:56:10.596: ERROR/AndroidRuntime(516): at java.lang.reflect.Method.invokeNative(Native Method)
11-06 12:56:10.596: ERROR/AndroidRuntime(516): at java.lang.reflect.Method.invoke(Method.java:521)
11-06 12:56:10.596: ERROR/AndroidRuntime(516): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-06 12:56:10.596: ERROR/AndroidRuntime(516): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-06 12:56:10.596: ERROR/AndroidRuntime(516): at dalvik.system.NativeStart.main(Native Method)
11-06 12:56:10.596: ERROR/AndroidRuntime(516): Caused by: java.lang.ClassCastException: android.widget.TextView
11-06 12:56:10.596: ERROR/AndroidRuntime(516): at balu.android.CommonNames.onCreate(CommonNames.java:31)
11-06 12:56:10.596: ERROR/AndroidRuntime(516): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-06 12:56:10.596: ERROR/AndroidRuntime(516): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
11-06 12:56:10.596: ERROR/AndroidRuntime(516): ... 11 more
11-06 12:56:10.616: WARN/ActivityManager(59): Force finishing activity balu.android/.CommonNames
11-06 12:56:10.626: WARN/ActivityManager(59): Force finishing activity balu.android/.Select
11-06 12:56:11.183: WARN/ActivityManager(59): Activity pause timeout for HistoryRecord{450af6e8 balu.android/.CommonNames}
11-06 12:56:20.036: WARN/ActivityManager(59): Launch timeout has expired, giving up wake lock!
11-06 12:56:20.125: WARN/ActivityManager(59): Activity idle timeout for HistoryRecord{450af6e8 balu.android/.CommonNames}
11-06 12:56:21.252: WARN/ActivityManager(59): Activity idle timeout for HistoryRecord{44fd7b98 balu.android/.BabyNamesAppActivity}
11-06 12:56:26.456: DEBUG/dalvikvm(132): GC_EXPLICIT freed 1211 objects/86976 bytes in 177ms
我認爲這是問題的根源。
https://github.com/Balu-Varanasi/BabyNamesApp/blob/master/src/balu/android/CommonNameTable.java https://github.com/Balu-Varanasi/BabyNamesApp/blob/master/src/balu/android/CommonNames.java
能否請你幫我解決這個問題?
把你的代碼中你得到這個異常> –