在onNewIntent Android中无法访问Edittext

时间:2013-10-01 08:07:49

标签: android android-intent android-activity

我试图访问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);

            }
        });

1 个答案:

答案 0 :(得分:0)

请检查onNewIntent它是否用于从backstack使用前一个Activity实例。如果您的edit1未初始化,则会显示NPE

修改

我理解的是

您的FirstPage.java是登录页面,登录后Home.java是您的主页,当您从主屏幕退出时,您来到FirstPage.java,然后您想要清除EditText凭证。

因此,如果是这种情况,那么您可以将noHistory用于FirstPage.java,这样它就不会留在backstack中,因此您无需跟踪backstack } Home.java中的正常背压手动操作。然后,您可以在注销时{/ 1}}开始

FirstPage.java