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.