我正在为我的网络服务开发一个 android 应用程序。
我在主要活动中添加了一个注册 TextView 并为 onClickListener 添加了以下代码:
mRegister.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(new Intent(LoginActivity.this, RegisterActivity.class));
}
});
点击注册TextView时,logcat中返回此错误:
01-01 01:36:29.443: E/AndroidRuntime(21558): FATAL EXCEPTION: main
01-01 01:36:29.443: E/AndroidRuntime(21558): java.lang.RuntimeException: Unable to start activity ComponentInfo{us.picbox/us.picbox.RegisterActivity}: java.lang.NullPointerException
01-01 01:36:29.443: E/AndroidRuntime(21558): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1830)
01-01 01:36:29.443: E/AndroidRuntime(21558): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1851)
01-01 01:36:29.443: E/AndroidRuntime(21558): at android.app.ActivityThread.access$1500(ActivityThread.java:132)
01-01 01:36:29.443: E/AndroidRuntime(21558): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1038)
01-01 01:36:29.443: E/AndroidRuntime(21558): at android.os.Handler.dispatchMessage(Handler.java:99)
01-01 01:36:29.443: E/AndroidRuntime(21558): at android.os.Looper.loop(Looper.java:150)
01-01 01:36:29.443: E/AndroidRuntime(21558): at android.app.ActivityThread.main(ActivityThread.java:4293)
01-01 01:36:29.443: E/AndroidRuntime(21558): at java.lang.reflect.Method.invokeNative(Native Method)
01-01 01:36:29.443: E/AndroidRuntime(21558): at java.lang.reflect.Method.invoke(Method.java:507)
01-01 01:36:29.443: E/AndroidRuntime(21558): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
01-01 01:36:29.443: E/AndroidRuntime(21558): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
01-01 01:36:29.443: E/AndroidRuntime(21558): at dalvik.system.NativeStart.main(Native Method)
01-01 01:36:29.443: E/AndroidRuntime(21558): Caused by: java.lang.NullPointerException
01-01 01:36:29.443: E/AndroidRuntime(21558): at us.picbox.RegisterActivity.onCreate(RegisterActivity.java:85)
01-01 01:36:29.443: E/AndroidRuntime(21558): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1072)
01-01 01:36:29.443: E/AndroidRuntime(21558): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1794)
01-01 01:36:29.443: E/AndroidRuntime(21558): ... 11 more
任何人都可以对这个问题有所了解吗?