我正在制作一个应用程序,但我需要一些帮助。在活动的 oncreate 实践中,我有以下代码:
try{
Bundle extras = getIntent().getExtras();
check = extras.getInt("checkpoint1");
}catch(NumberFormatException nfe){
check = 0;
}
在 oncreate 中,您尝试从另一个活动中获取变量检查的值,如果尝试不成功,则必须将此变量设置为零。但是现在编写的代码给了我错误。你可以帮帮我吗?
你的帮助给了我同样的错误:
E/AndroidRuntime(3028): FATAL EXCEPTION: main
E/AndroidRuntime(3028): java.lang.RuntimeException: Unable to start activity ComponentInfo{it.BisMagdev.notesRainbow/it.BisMagdev.notesRainbow.livello4}: java.lang.NullPointerException
E/AndroidRuntime(3028): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
E/AndroidRuntime(3028): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
E/AndroidRuntime(3028): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
E/AndroidRuntime(3028): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
E/AndroidRuntime(3028): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(3028): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime(3028): at android.app.ActivityThread.main(ActivityThread.java:4627)
E/AndroidRuntime(3028): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(3028): at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime(3028): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
E/AndroidRuntime(3028): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
E/AndroidRuntime(3028): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(3028): Caused by: java.lang.NullPointerException
E/AndroidRuntime(3028): at it.BisMagdev.notesRainbow.livello4.onCreate(livello4.java:60)
E/AndroidRuntime(3028): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
E/AndroidRuntime(3028): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
E/AndroidRuntime(3028): ... 11 more