-1

我试图访问中的编辑文本,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();

    }

注销代码

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);

            }
        });
4

1 回答 1

0

请检查onNewIntent它用于使用Activity来自 backstack 的前一个实例。如果你edit1没有初始化它会给你NPE

编辑

我的理解是

FirstPage.java是登录页面,并且Home.java是您登录后的主页,当您从主屏幕注销时,您会进入FirstPage.java然后您想要清除您EditText的凭据。

因此,如果是这种情况,那么您可以使用noHistoryforFirstPage.java以便它不会留在您的内部backstack,并且您不必backstackHome.java. 然后你可以开始你FirstPage.java的注销像

Intent intent = new Intent(Home.this,FirstPage.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK)); 
startActivity(intent)
于 2013-10-01T08:20:58.237 回答