我正在制作一个登录系统,我不知道为什么会发生这种情况。我该如何解决这个问题?这是有关 NullPointerException 的类的一部分。
final TextView registerButton = (TextView)findViewById(R.id.registerButton);
registerButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent registerIntent=new Intent(LoginActivity.this, RegisterActivity.class);
LoginActivity.this.startActivity(registerIntent);
}
});
以下是来自 logcat 的上下文。
03-22 10:37:13.066 8500-8500/? E/dex2oat: Failed to create oat file: /data/dalvik-cache/arm/data@[email protected]@[email protected]: Permission denied
03-22 10:37:13.141 3897-3897/? E/SDAgentPackageStateReceiver: Not going to handle 'com.example.gibong.capstone'!
03-22 10:37:13.166 6707-6707/? E/Launcher.Model: onPackageAdded :com.example.gibong.capstone
03-22 10:37:13.296 8526-8526/? E/dex2oat: Failed to create oat file: /data/dalvik-cache/arm/data@[email protected]@[email protected]: Permission denied
03-22 10:37:13.341 8533-8533/? E/dex2oat: Failed to create oat file: /data/dalvik-cache/arm/data@[email protected]@[email protected]: Permission denied
03-22 10:37:13.391 8539-8539/? E/dex2oat: Failed to create oat file: /data/dalvik-cache/arm/data@[email protected]@[email protected]: Permission denied
03-22 10:37:13.461 8543-8543/? E/dex2oat: Failed to create oat file: /data/dalvik-cache/arm/data@[email protected]@[email protected]: Permission denied
03-22 10:37:13.516 8561-8561/? E/dex2oat: Failed to create oat file: /data/dalvik-cache/arm/data@[email protected]@[email protected]: Permission denied
03-22 10:37:13.566 8567-8567/? E/dex2oat: Failed to create oat file: /data/dalvik-cache/arm/data@[email protected]@[email protected]: Permission denied
03-22 10:37:13.616 8572-8572/? E/dex2oat: Failed to create oat file: /data/dalvik-cache/arm/data@[email protected]@[email protected]: Permission denied
03-22 10:37:13.666 8577-8577/? E/dex2oat: Failed to create oat file: /data/dalvik-cache/arm/data@[email protected]@[email protected]: Permission denied
03-22 10:37:13.716 8581-8581/? E/dex2oat: Failed to create oat file: /data/dalvik-cache/arm/data@[email protected]@[email protected]: Permission denied
03-22 10:37:13.771 8587-8587/? E/dex2oat: Failed to create oat file: /data/dalvik-cache/arm/data@[email protected]@[email protected]: Permission denied
03-22 10:37:14.511 8474-8474/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.gibong.capstone, PID: 8474
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.gibong.capstone/com.example.gibong.capstone.LoginActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3253)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349)
at android.app.ActivityThread.access$1100(ActivityThread.java:221)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7225)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
at com.example.gibong.capstone.LoginActivity.onCreate(LoginActivity.java:35)
at android.app.Activity.performCreate(Activity.java:6876)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3206)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349)
at android.app.ActivityThread.access$1100(ActivityThread.java:221)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7225)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
由于我的英语和本网站不流利,我为我对英语和文字风格的使用不当而道歉。
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setOnClickListener(android.view.View$OnClickListener)' on a null object
在下面的行中
final TextView registerButton = (TextView)findViewById(R.id.registerButton);
你通过正确的id
吗?检查R.id.registerButton
您的 xml 文件中是否存在
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句