我是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);
}
}
你是如何創建數組? 「NullPointerException」意味着你試圖使用一個空值的引用。既然你說過直到你開始使用數組纔會發生,我猜你沒有初始化它們。 – DeeV
其實我認爲空指針異常是在725行(GolfScoreActivity.SetupClickListeners(GolfScoreActivity.java:725))...因此,很高興看到(說)從551到725 +/- ... – Torid
public void SetupClickListeners(){(0; holeNum = 1; holeNum <18; holeNum ++){ scorePlayHole [currentPlayerNum-1] [holeNum-1] .addTextChangedListener(this); } 對(INT I = 1;我
John