我试图访问onNewIntent()
中的编辑文本,但它却抛出了空指针异常。
例外:
10-01 13:20:03.516: E/AndroidRuntime(18170): FATAL EXCEPTION: main
10-01 13:20:03.516: E/AndroidRuntime(18170): java.lang.NullPointerException
10-01 13:20:03.516: E/AndroidRuntime(18170): at com.iween.exampleTest.FirstPage.onNewIntent(FirstPage.java:177)
10-01 13:20:03.516: E/AndroidRuntime(18170): at android.app.Instrumentation.callActivityOnNewIntent(Instrumentation.java:1155)
10-01 13:20:03.516: E/AndroidRuntime(18170): at android.app.ActivityThread.deliverNewIntents(ActivityThread.java:2279)
10-01 13:20:03.516: E/AndroidRuntime(18170): at android.app.ActivityThread.performNewIntents(ActivityThread.java:2292)
10-01 13:20:03.516: E/AndroidRuntime(18170): at android.app.ActivityThread.handleNewIntent(ActivityThread.java:2301)
10-01 13:20:03.516: E/AndroidRuntime(18170): at android.app.ActivityThread.access$1400(ActivityThread.java:149)
10-01 13:20:03.516: E/AndroidRuntime(18170): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1371)
10-01 13:20:03.516: E/AndroidRuntime(18170): at android.os.Handler.dispatchMessage(Handler.java:99)
10-01 13:20:03.516: E/AndroidRuntime(18170): at android.os.Looper.loop(Looper.java:153)
10-01 13:20:03.516: E/AndroidRuntime(18170): at android.app.ActivityThread.main(ActivityThread.java:4987)
10-01 13:20:03.516: E/AndroidRuntime(18170): at java.lang.reflect.Method.invokeNative(Native Method)
10-01 13:20:03.516: E/AndroidRuntime(18170): at java.lang.reflect.Method.invoke(Method.java:511)
10-01 13:20:03.516: E/AndroidRuntime(18170): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:821)
10-01 13:20:03.516: E/AndroidRuntime(18170): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
10-01 13:20:03.516: E/AndroidRuntime(18170): at dalvik.system.NativeStart.main(Native Method)
onNewItent代码
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
edit1.getText().clear();
}
LogoutCOde
clickToLogout.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent(Home.this,
Firstpage.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
});
答案 0 :(得分:0)
请检查onNewIntent它是否用于从backstack使用前一个Activity
实例。如果您的edit1
未初始化,则会显示NPE
。
修改强>
我理解的是
您的FirstPage.java
是登录页面,登录后Home.java
是您的主页,当您从主屏幕退出时,您来到FirstPage.java
,然后您想要清除EditText
凭证。
因此,如果是这种情况,那么您可以将noHistory
用于FirstPage.java
,这样它就不会留在backstack
中,因此您无需跟踪backstack
} Home.java
中的正常背压手动操作。然后,您可以在注销时{/ 1}}开始
FirstPage.java