Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Attempt to invoke interface method 'void android.view.inputmethod.InputConnection.closeConnection()' on a null object reference

Tags:

android

environment:Android Studio 3.1.1 code:

import com.firebase.ui.auth.AuthUI;
...
    private void startSignIn()
    {
        // Sign in with FirebaseUI
        Intent intent = AuthUI.getInstance()
                .createSignInIntentBuilder()
                .setIsSmartLockEnabled(false)
                .setAvailableProviders(Arrays.asList(
                        new AuthUI.IdpConfig.EmailBuilder().build(),
                        new AuthUI.IdpConfig.GoogleBuilder().build()
                ))
                .build();

        startActivityForResult(intent, RC_SIGN_IN);
        mViewModel.setIsSigningIn(true);

    }

The bug appeared when I deleted my account in firebase>Authentication>USERS and tried to sign up with the same email again.

When I choose sign in with email and input an email and push "Next" the app has stopped...

it should be creat an new account

errorcode:

java.lang.NullPointerException: Attempt to invoke interface method 'void android.view.inputmethod.InputConnection.closeConnection()' on a null object reference
        at android.view.inputmethod.InputConnectionWrapper.closeConnection(InputConnectionWrapper.java:270)
        at com.android.internal.view.IInputConnectionWrapper.executeMessage(IInputConnectionWrapper.java:541)
        at com.android.internal.view.IInputConnectionWrapper$MyHandler.handleMessage(IInputConnectionWrapper.java:85)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6494)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

any idea what's goes wrong?

like image 283
Jack Wilson Avatar asked Apr 18 '18 05:04

Jack Wilson


4 Answers

It seems like that's the problem with Android Profiler.

Because we don't need to enable advanced profiling explicitly for API >= 26, after you open "Android Profiler" tab in Android Studio, it catches your app and binds to it.

What helped me, is going to "Android Profiler" tab, and clicking "End Session" in top-right corner.

See the screenshot

like image 139
Nikita Kraev Avatar answered Oct 31 '22 18:10

Nikita Kraev


This was happening to me on a real device.

I had an EditText that I programmatically clear and hide soft keyboard after user submitted the text. And when user switched to another Fragment, InputConnection was attempted to be closed but rarely it was null.

Calling EditText.clearFocus() after text is submitted fixed the issue for me as InputConnection.closeConnection called right away, instead of onCreateView of another Fragment.

Calling clearFocus at onPause of the Fragment/Activity with the EditText should also work.

like image 34
Sfseyhan Avatar answered Oct 31 '22 18:10

Sfseyhan


Finally, I solve the problem by uninstalling the app on the simulator,

and run and install the app again.

it seems like that problem caused by the cache, I'm not sure

like image 2
Jack Wilson Avatar answered Oct 31 '22 16:10

Jack Wilson


I think this issue is related to the simulation environment. I had similar problem in the emulator but not on my phone.

If I used the mouse in the simulator, it crashed when I change fragments, but if I only use the keyboard, no crash occurs.

Solution: I updated the emulator and the problem disappeared.

like image 1
Makketronix Avatar answered Oct 31 '22 17:10

Makketronix