我在向代码添加第三个活动后遇到错误。产生错误的代码如下:
public void onClick(View v) {
Intent callIncomeIntent = new Intent(v.getContext(), Add_Income.class);
startActivityForResult(callIncomeIntent, 0);
}
});
生成错误:
11-18 13:59:29.137: D/libEGL(13211): loaded /vendor/lib/egl/libEGL_adreno.so
11-18 13:59:29.147: D/libEGL(13211): loaded /vendor/lib/egl/libGLESv1_CM_adreno.so
11-18 13:59:29.147: D/libEGL(13211): loaded /vendor/lib/egl/libGLESv2_adreno.so
11-18 13:59:29.157: I/Adreno-EGL(13211): <qeglDrvAPI_eglInitialize:316>: EGL 1.4 QUALCOMM build: (CL4169980)
11-18 13:59:29.157: I/Adreno-EGL(13211): OpenGL ES Shader Compiler Version: 17.01.10.SPL
11-18 13:59:29.157: I/Adreno-EGL(13211): Build Date: 11/04/13 Mon
11-18 13:59:29.157: I/Adreno-EGL(13211): Local Branch:
11-18 13:59:29.157: I/Adreno-EGL(13211): Remote Branch:
11-18 13:59:29.157: I/Adreno-EGL(13211): Local Patches:
11-18 13:59:29.157: I/Adreno-EGL(13211): Reconstruct Branch:
11-18 13:59:29.197: D/OpenGLRenderer(13211): Enabling debug mode 0
11-18 13:59:31.800: D/AndroidRuntime(13211): Shutting down VM
11-18 13:59:31.800: W/dalvikvm(13211): threadid=1: thread exiting with uncaught exception (group=0x415b58b0)
11-18 13:59:31.830: E/AndroidRuntime(13211): FATAL EXCEPTION: main
11-18 13:59:31.830: E/AndroidRuntime(13211): java.lang.RuntimeException: Unable to start activity ComponentInfo{tei.ptix.income_management/tei.ptix.income_management.Add_Income}: java.lang.NullPointerException
11-18 13:59:31.830: E/AndroidRuntime(13211): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2266)
11-18 13:59:31.830: E/AndroidRuntime(13211): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2316)
11-18 13:59:31.830: E/AndroidRuntime(13211): at android.app.ActivityThread.access$600(ActivityThread.java:150)
11-18 13:59:31.830: E/AndroidRuntime(13211): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1298)
11-18 13:59:31.830: E/AndroidRuntime(13211): at android.os.Handler.dispatchMessage(Handler.java:99)
11-18 13:59:31.830: E/AndroidRuntime(13211): at android.os.Looper.loop(Looper.java:213)
11-18 13:59:31.830: E/AndroidRuntime(13211): at android.app.ActivityThread.main(ActivityThread.java:5225)
11-18 13:59:31.830: E/AndroidRuntime(13211): at java.lang.reflect.Method.invokeNative(Native Method)
11-18 13:59:31.830: E/AndroidRuntime(13211): at java.lang.reflect.Method.invoke(Method.java:525)
11-18 13:59:31.830: E/AndroidRuntime(13211): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:741)
11-18 13:59:31.830: E/AndroidRuntime(13211): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
11-18 13:59:31.830: E/AndroidRuntime(13211): at dalvik.system.NativeStart.main(Native Method)
11-18 13:59:31.830: E/AndroidRuntime(13211): Caused by: java.lang.NullPointerException
11-18 13:59:31.830: E/AndroidRuntime(13211): at tei.ptix.income_management.Add_Income.onCreate(Add_Income.java:31)
11-18 13:59:31.830: E/AndroidRuntime(13211): at android.app.Activity.performCreate(Activity.java:5133)
11-18 13:59:31.830: E/AndroidRuntime(13211): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
11-18 13:59:31.830: E/AndroidRuntime(13211): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2230)
11-18 13:59:31.830: E/AndroidRuntime(13211): ... 11 more
当我将鼠标悬停在Intent上时,它会显示以下文字: android.content.Intent.Intent(Context packageContext,Class 注意:此元素没有附加源,并且在附加的Javadoc中找不到Javadoc。
有人可以建议一个解决方案吗?
提前致谢。
答案 0 :(得分:1)
11-18 13:59:31.830: E/AndroidRuntime(13211): Caused by: java.lang.NullPointerException
11-18 13:59:31.830: E/AndroidRuntime(13211): at tei.ptix.income_management.Add_Income.onCreate(Add_Income.java:31)
有人写了一个名为tei.ptix.income_management.Add_Income
的Java类。从上面的代码段开始,它似乎是Activity
的子类。在其onCreate()
方法的Add_Income.java
第31行中,您有一个NullPointerException
。
因此,请查看Add_Income.java
的第31行,并确定为什么要在null
的某个参数,变量或数据成员上调用方法。如果您无法确定原因null
,或者可以考虑询问您在活动中提供源代码的问题,或者至少在onCreate()
方法中指出哪一行是第31行,并且有人可能会帮助您确定null
是什么以及为什么。