运行时异常

时间:2011-07-15 16:36:05

标签: android runtimeexception

我是Java编程的新手,这让我很难过。我的应用程序启动时出现运行时异常和强制关闭。在我将大量代码编写成数组而不是单个代码之前,它确实有效。有人能给我一些线索可能有什么问题吗?

07-15 16:30:29.441: INFO/ARMAssembler(61): generated scanline__00000177:03515104_00001001_00000000 [ 91 ipp] (114 ins) at [0x38fe50:0x390018] in 1735976 ns
07-15 16:30:29.551: ERROR/gralloc(61): [unregister] handle 0x4910f0 still locked (state=40000001)
07-15 16:30:58.871: DEBUG/AndroidRuntime(229): Shutting down VM
07-15 16:30:58.871: WARN/dalvikvm(229): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
07-15 16:30:58.871: ERROR/AndroidRuntime(229): Uncaught handler: thread main exiting due to uncaught exception
07-15 16:30:59.252: ERROR/AndroidRuntime(229): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.golfandroid/com.example.golfandroid.GolfScoreActivity}: java.lang.NullPointerException
07-15 16:30:59.252: ERROR/AndroidRuntime(229):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
07-15 16:30:59.252: ERROR/AndroidRuntime(229):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
07-15 16:30:59.252: ERROR/AndroidRuntime(229):     at android.app.ActivityThread.access$2200(ActivityThread.java:119)
07-15 16:30:59.252: ERROR/AndroidRuntime(229):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
07-15 16:30:59.252: ERROR/AndroidRuntime(229):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-15 16:30:59.252: ERROR/AndroidRuntime(229):     at android.os.Looper.loop(Looper.java:123)
07-15 16:30:59.252: ERROR/AndroidRuntime(229):     at android.app.ActivityThread.main(ActivityThread.java:4363)
07-15 16:30:59.252: ERROR/AndroidRuntime(229):     at java.lang.reflect.Method.invokeNative(Native Method)
07-15 16:30:59.252: ERROR/AndroidRuntime(229):     at java.lang.reflect.Method.invoke(Method.java:521)
07-15 16:30:59.252: ERROR/AndroidRuntime(229):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
07-15 16:30:59.252: ERROR/AndroidRuntime(229):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
07-15 16:30:59.252: ERROR/AndroidRuntime(229):     at dalvik.system.NativeStart.main(Native Method)
07-15 16:30:59.252: ERROR/AndroidRuntime(229): Caused by: java.lang.NullPointerException
07-15 16:30:59.252: ERROR/AndroidRuntime(229):     at com.example.golfandroid.GolfScoreActivity.SetupClickListeners(GolfScoreActivity.java:725)
07-15 16:30:59.252: ERROR/AndroidRuntime(229):     at com.example.golfandroid.GolfScoreActivity.onCreate(GolfScoreActivity.java:551)
07-15 16:30:59.252: ERROR/AndroidRuntime(229):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-15 16:30:59.252: ERROR/AndroidRuntime(229):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
07-15 16:30:59.252: ERROR/AndroidRuntime(229):     ... 11 more
07-15 16:30:59.432: INFO/Process(61): Sending signal. PID: 229 SIG: 3
07-15 16:30:59.462: INFO/dalvikvm(229): threadid=7: reacting to signal 3
07-15 16:30:59.753: INFO/dalvikvm(229): Wrote stack trace to '/data/anr/traces.txt'

代码:

public void SetupClickListeners(){ 
    for(int holeNum=1; holeNum<18; holeNum++){ 
        scorePlayHole[currentPlayerNum-1][holeNum-1].addTextChangedListener(this); 
    } 
    for(int i=1; i<currentPlayerNum*4; i++){ 
        NextPlayerHoleButton[currentPlayerNum-1][i].setOnClickListener(this); 
    } 
} 

3 个答案:

答案 0 :(得分:1)

这只是在黑暗中刺伤,因为我只有堆栈跟踪而不是相关来源。

你看过这个源文件了吗? GolfScoreActivity.java 第725行

看起来您正在设置Click Listener,但某些内容未初始化且为Null

答案 1 :(得分:0)

在没有看到代码的情况下在黑暗中拍摄很难说 - 但是如果你已经将代码转换为使用数组,你是否还记得新数组本身以及进入数组的对象?

答案 2 :(得分:0)

07-15 16:30:59.252: ERROR/AndroidRuntime(229): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.golfandroid/com.example.golfandroid.GolfScoreActivity}: java.lang.NullPointerException

这实际上不是运行时异常。这是一个包装空指针异常的运行时异常。根本原因是空指针:

检查完代码后,其中任何一个都可能是null,从而导致空指针异常。

scorePlayHole
scorePlayHole[currentPlayerNum-1]
scorePlayHole[currentPlayerNum-1][holeNum-1]
NextPlayerHoleButton
NextPlayerHoleButton[currentPlayerNum-1]
NextPlayerHoleButton[currentPlayerNum-1][i]