Search code examples
androidandroid-edittextinputconnection

EditText: NPE in InputConnection.reportFullscreenMode


Note: the problem I'm trying to work around is restricted to Rockchip RK312X based no-name China tablets running SDK 23 (Marshmallow). No other devices seem to be affected, but unfortunately I'm forced to use those crappy devices (which also have serial ports on them btw) for dev & demo purposes.

The problem: when any layout containing any subclass of EditText is removed from the window (finish() is called in an Activity, a custom DialogFragment containing an EditText is dismissed etc.) the app crashes giving the following stack trace (complete output):

java.lang.NullPointerException: Attempt to invoke interface method 'boolean android.view.inputmethod.InputConnection.reportFullscreenMode(boolean)' on a null object reference
    at android.view.inputmethod.InputConnectionWrapper.reportFullscreenMode(InputConnectionWrapper.java:122)
    at com.android.internal.view.IInputConnectionWrapper.executeMessage(IInputConnectionWrapper.java:416)
    at com.android.internal.view.IInputConnectionWrapper$MyHandler.handleMessage(IInputConnectionWrapper.java:78)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:148)
    at android.app.ActivityThread.main(ActivityThread.java:5417)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:746)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)

Here's a very simple layout example:

 <android.support.design.widget.TextInputLayout
        android:id="@+id/tilConnectionToken"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/tvSetupInfo"
        android:layout_marginEnd="15dp"
        android:layout_marginStart="15dp"
        android:layout_marginTop="10dp"
        android:ems="10"
        app:errorEnabled="true"
        android:hint="@string/conn_token">

        <android.support.design.widget.TextInputEditText
            android:id="@+id/etConnectionToken"
            android:maxLines="1"
            android:inputType="text"
            android:imeOptions="actionDone"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
  </android.support.design.widget.TextInputLayout>

The Activity doesn't really do anything:

class ConnectWizardActivity : AppCompatActivity(), View.OnClickListener {

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_setup_wiz)
    btnCancel.setOnClickListener(this)
}


override fun onClick(v: View) {
    when (v.id) {
        R.id.btnCancel -> finish()
    }
  }
}

Calling finish() already causes a crash with the stack trace provided above. What I've tried before finishing the Activity:

  • clearing the focus from the EditText
  • hiding the soft keyboard
  • completely removing the EditText (and other Views) from its container

The same NPE keeps occurring. As I've said before, the issue is not restricted to a specific Activity or a specific subclass of EditText - it happens everywhere on those devices.

What I think is normally supposed to happen: this log for example comes from a Huawei MediaPad T3, no crashes

W/IInputConnectionWrapper: finishComposingText on inactive InputConnection

Any ideas how to work around the NPE on no-name Marshmallow devices?


Solution

  • I was having the same issue and ended up discovering that "Advance profiling" feature of Android Studio was the culprit.

    This answer explains how to disable the option. Hope this helps!