运行时异常
我是 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);
}
}
I am new to Java programming and this has me stumped. I get a runtime exception and a force close when my app starts. It did work before I made a lot of the code into arrays rather than singles. Can someone give me a clue what might be wrong?
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'
Code:
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);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这只是在黑暗中刺探,因为我只有堆栈跟踪,没有相关来源。
你看过这个源文件吗?
GolfScoreActivity.java
行号 725
看起来您正在设置 Click Listener,但某些内容未初始化且为 Null
This is just a stab in the dark since I only have the stack trace and not the relevant source.
Did you look at this source file?
GolfScoreActivity.java
Line number 725
Looks like you are setting up a Click Listener but something wasn't initialized and is Null
在黑暗中拍摄,因为没有看到代码,所以很难说 - 但如果您已将代码转换为使用数组,您是否记得更新数组本身以及进入数组的对象?
Shot in the dark as without seeing the code it's hard to tell - but if you have converted you code to use arrays, did you remember to new the array itself, as well as the objects that go into the array?
<代码>
07-15 16:30:59.252:错误/AndroidRuntime(229):java.lang.RuntimeException:无法启动活动ComponentInfo {com.example.golfandroid/com.example.golfandroid.GolfScoreActivity}:java.lang.NullPointerException
这并不是真正的运行时异常。它是一个包装空指针异常的运行时异常。根本原因是空指针:
检查代码后,其中任何一个都可能为
null
,从而导致空指针异常。<代码>
得分PlayHole
ScorePlayHole[currentPlayerNum-1]
ScorePlayHole[currentPlayerNum-1][holeNum-1]
NextPlayerHoleButton
NextPlayerHoleButton[currentPlayerNum-1]
NextPlayerHoleButton[currentPlayerNum-1][i]
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
This isn't really a runtime exception. It's a runtime exception that wraps a null pointer exception. The root cause is a null pointer:
After examining your code, any one of these could be
null
and therefore causing the null pointer exception.scorePlayHole
scorePlayHole[currentPlayerNum-1]
scorePlayHole[currentPlayerNum-1][holeNum-1]
NextPlayerHoleButton
NextPlayerHoleButton[currentPlayerNum-1]
NextPlayerHoleButton[currentPlayerNum-1][i]