Android中的模式/状态

时间:2011-07-18 01:24:18

标签: java android

我正在开发一款针对Android的游戏,我正试图在月球着陆器示例中添加不同的游戏模式/状态。我遇到了问题,因为我的活动是从一个标题屏幕开始,有几个按钮,一个按下来玩游戏。当您按下播放按钮时,应用程序崩溃。无论如何,我可以正确地为我的游戏添加不同的模式/状态。

EDIT:

07-18 03:40:24.210: ERROR/AndroidRuntime(224): Uncaught handler: thread main exiting due to uncaught exception
07-18 03:40:24.391: ERROR/AndroidRuntime(224): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.hitmanassault/com.android.hitmanassault.Hitman}: java.lang.ClassCastException: android.widget.TextView
07-18 03:40:24.391: ERROR/AndroidRuntime(224):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
07-18 03:40:24.391: ERROR/AndroidRuntime(224):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
07-18 03:40:24.391: ERROR/AndroidRuntime(224):     at android.app.ActivityThread.access$2200(ActivityThread.java:119)
07-18 03:40:24.391: ERROR/AndroidRuntime(224):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
07-18 03:40:24.391: ERROR/AndroidRuntime(224):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-18 03:40:24.391: ERROR/AndroidRuntime(224):     at android.os.Looper.loop(Looper.java:123)
07-18 03:40:24.391: ERROR/AndroidRuntime(224):     at android.app.ActivityThread.main(ActivityThread.java:4363)
07-18 03:40:24.391: ERROR/AndroidRuntime(224):     at java.lang.reflect.Method.invokeNative(Native Method)
07-18 03:40:24.391: ERROR/AndroidRuntime(224):     at java.lang.reflect.Method.invoke(Method.java:521)
07-18 03:40:24.391: ERROR/AndroidRuntime(224):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
07-18 03:40:24.391: ERROR/AndroidRuntime(224):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
07-18 03:40:24.391: ERROR/AndroidRuntime(224):     at dalvik.system.NativeStart.main(Native Method)
07-18 03:40:24.391: ERROR/AndroidRuntime(224): Caused by: java.lang.ClassCastException: android.widget.TextView
07-18 03:40:24.391: ERROR/AndroidRuntime(224):     at com.android.hitmanassault.Hitman.onCreate(Hitman.java:48)
07-18 03:40:24.391: ERROR/AndroidRuntime(224):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-18 03:40:24.391: ERROR/AndroidRuntime(224):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
07-18 03:40:24.391: ERROR/AndroidRuntime(224):     ... 11 more

1 个答案:

答案 0 :(得分:0)

在Hitman.java,第48行

 ERROR/AndroidRuntime(224): Caused by: java.lang.ClassCastException: android.widget.TextView 07-18 03:40:24.391: ERROR/AndroidRuntime(224): at com.android.hitmanassault.Hitman.onCreate(Hitman.java:48) 07-18 03:40:24.391: 

您从View层次结构创建/取消的对象可能不是TextView。检查您的xml以了解正确的类型。