2

When changing the fragment with EditTexts in an activity,"java.lang.NullPointerException" happens (full stack trace is below). This happens only in debug mode. I have searched the web and the proposed solutions was unchecking Advanced Profiling (< API 26). But in my case, that option has already been unchecked and I am targeting API level 27.

Is there a solution for this?

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:440)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

Environment:

compileSdkVersion 27
minSdkVersion 23
targetSdkVersion 27
buildToolsVersion "27.0.3"
compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}
Android Studio 3.1.1
Build #AI-173.4697961, built on April 4, 2018
JRE: 1.8.0_152-release-1024-b02 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Android 8.1.0

Added

I had set the filter to "Error" so I did not see these, but when I changed it to "Verbose", I could see that these things happening right before the crash, when I tried to replace the fragment.

D/AutofillManager: notifyViewVisibilityChanged(): id=1073741873 isVisible=true
D/AutofillManager: notifyViewVisibilityChanged(): id=1073741875 isVisible=true
D/AutofillManager: notifyViewVisibilityChanged(): id=1073741874 isVisible=true
D/AutofillManager: notifyViewVisibilityChanged(): id=1073741876 isVisible=true
D/AutofillManager: notifyViewVisibilityChanged(): id=1073741877 isVisible=true
D/AutofillManager: notifyViewVisibilityChanged(): id=1073741878 isVisible=true
D/AutofillManager: notifyViewVisibilityChanged(): id=1073741879 isVisible=true
D/AutofillManager: notifyViewVisibilityChanged(): id=1073741891 isVisible=true
D/AutofillManager: notifyViewVisibilityChanged(): id=1073741880 isVisible=true
D/AutofillManager: notifyViewVisibilityChanged(): id=1073741881 isVisible=true
D/AutofillManager: notifyViewVisibilityChanged(): id=1073741882 isVisible=true
D/AutofillManager: notifyViewVisibilityChanged(): id=1073741883 isVisible=true
D/AutofillManager: notifyViewVisibilityChanged(): id=1073741884 isVisible=true
D/AutofillManager: notifyViewVisibilityChanged(): id=1073741885 isVisible=true
D/AutofillManager: notifyViewVisibilityChanged(): id=1073741886 isVisible=true
D/AutofillManager: notifyViewVisibilityChanged(): id=1073741887 isVisible=true
D/AutofillManager: notifyViewVisibilityChanged(): id=1073741888 isVisible=true
D/AutofillManager: notifyViewVisibilityChanged(): id=1073741889 isVisible=true
D/AutofillManager: notifyViewVisibilityChanged(): id=1073741890 isVisible=true
I/Choreographer: Skipped 104 frames!  The application may be doing too much work on its main thread.
D/AutofillManager: notifyViewVisibilityChanged(): id=1073741824 isVisible=false
D/AutofillManager: notifyViewVisibilityChanged(): id=1073741825 isVisible=false
D/AndroidRuntime: Shutting down VM

I used this code to replace the fragment to another one.

    val transaction = supportFragmentManager.beginTransaction()
    transaction.replace(R.id.frame, Fragment2.newInstance());
    transaction.commit()

Added 2.

If I comment out the EditText's, then this crash does not happen. I think this has something to do with the AutoFill (Oreo), so I wanted to isolate this problem by creating a simple project that can reproduce this problem, but unfortunately, I could not get the AutoFill to work on it. AutoFill was automatically enabled on my original project, so I am not sure by which conditions it gets enabled.


Added 3.

It also happens on Android 7.1 (emulator). Since 7.1 does not have AutoFill, I think it is not related to AutoFill. I have to investigate more.

Damn Vegetables
  • 11,484
  • 13
  • 80
  • 135
  • Can be related with this issue: https://stackoverflow.com/q/49623336/3669559 – Oğuzhan Döngül Apr 16 '18 at 15:00
  • Who downvoted this good question? – Khemraj Sharma Apr 16 '18 at 15:01
  • Probably the person who marked it to be closed as off-topic. The code used not to cause this crash, and I discovered this only today. So, I am guessing this has something to to the latest version of Android Studio or SDK. I think this is related to programming, as someone else may have the same problem. Is this kind of question now allowed? – Damn Vegetables Apr 16 '18 at 16:01
  • Funny enough, I saw the same crash today, when working with Fragments that contained an EditText and I didn’t do anything fancy afaik. But I also didn’t update AS (I’m on 3.1-stable): Android Studio 3.1 Build #AI-173.4670197, built on March 21, 2018 JRE: 1.8.0_152-release-1024-b01 x86_64 JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o Mac OS X 10.13.4 – Martin Marconcini Apr 16 '18 at 17:57
  • have you find any solution to this as I am still getting this problem rest everything is same as your code – Cyph3rCod3r May 30 '18 at 06:44
  • No, I am still experiencing this with the latest version. The only workaround is compiling it in Release mode. – Damn Vegetables May 30 '18 at 10:49

0 Answers0