Jack Wilson
Jack Wilson

Reputation: 6245

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

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?

Upvotes: 21

Views: 12023

Answers (7)

Enes Aldemir
Enes Aldemir

Reputation: 101

I tried all the solutions from this thread however problem was not resolved.

After I encountered with this blog post. As it is suggested in the blog post, I have changed the build variants from debug to release and problem is solved.

You should remove debug application from device completely before installing the release version.

Upvotes: 0

Sandeep PC
Sandeep PC

Reputation: 867

Observed this issue when removing current fragment and showing different fragment.

After trying different methods : The issue was observed only when the device is connected in debug mode.

NPE : Attempt to invoke interface method 'void android.view.inputmethod.InputConnection.closeConnection()' on a null object reference -> Crashing when closing connection with EditText (After different observation I got this conclusion)

Resolution : None - Works fine in normal condition on device (Without debug mode)

Other Solution : Update Android Studio to latest

or

Go to Edit configuration settings -> Profiling -> Enable advanced profiling

Upvotes: 0

Nikita Kraev
Nikita Kraev

Reputation: 1129

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

Upvotes: 21

qix
qix

Reputation: 7902

I had a very similar problem, and @Sfseyhan's suggestion to calling clearFocus() in onPause() didn't fix things (nor did clearing my View.OnFocusChangeListeners). I received on of the two exceptions fairly consistently, whenever the soft keyboard was showing with focus on the EditText:

  • If editing, but then launching a new Activity: java.lang.NullPointerException: Attempt to invoke interface method 'boolean android.view.inputmethod.InputConnection.finishComposingText()' on a null object reference

and

  • If editing, but then pressed the Home button to return to the launcher: java.lang.NullPointerException: Attempt to invoke interface method 'boolean android.view.inputmethod.InputConnection.reportFullscreenMode(boolean)' on a null object reference

Looks like the actual issue is with Android Studio (https://issuetracker.google.com/issues/77764953). I was using v3.1.3, but as the issue notes, they put a fix in as of Android Studio 3.2 Canary 18. I have verified on my end with Android Studio 3.2 Beta 2 that I no longer have the crashes.

Upvotes: 1

Sfseyhan
Sfseyhan

Reputation: 1351

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.

Upvotes: 20

Makketronix
Makketronix

Reputation: 1460

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.

Upvotes: 1

Jack Wilson
Jack Wilson

Reputation: 6245

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

Upvotes: 2

Related Questions