Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android 8.0 Oreo crash on focusing TextInputEditText

After updating some of our devices to android 8.0 , upon focusing on a TextInputEditText field inside of a TextInputLayout, the app crashes with this Exception:

Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'void
android.view.View.getBoundsOnScreen(android.graphics.Rect)' on a null object reference
at android.app.assist.AssistStructure$WindowNode.(AssistStructure.java)
at android.app.assist.AssistStructure.(AssistStructure.java)
at android.app.ActivityThread.handleRequestAssistContextExtras(ActivityThread.java:3035)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1807)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)

When we go to android Settings -> System -> Languages & input -> Advanced -> Auto-fill service -> None , then focusing on the TextInputEditText / TextInputLayout no longer crashes.

How can we prevent the crash from happening without having to disable the new 8.0 Auto-fill service on the devices?

like image 654
jesobremonte Avatar asked Aug 23 '17 13:08

jesobremonte


3 Answers

I ran into this too. It turns out the issue was caused by setting the hint text on the EditText nested inside the TextInputLayout.

I did some digging and found this nugget in the 26.0.0 Beta 2 release notes. Android Support Release Notes June 2017

TextInputLayout must set hints on onProvideAutofillStructure()

That led me to try setting the hint on the TextInputLayout instead of the nested EditText.

This resolved the crashing issue for me. Example:

<android.support.design.widget.TextInputLayout
    android:id="@+id/textInputLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="Some Hint Text"
    android.support.design:hintAnimationEnabled="true"
    android.support.design:hintEnabled="true"
    android.support.design:layout_marginTop="16dp">

    <android.support.design.widget.TextInputEditText
        android:id="@+id/editText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

</android.support.design.widget.TextInputLayout>

I posted this as an answer here as I mixed up bookmarks. Sorry for posting the same answer twice.

like image 118
Azethoth Avatar answered Nov 12 '22 20:11

Azethoth


Add below mentioned attribute in your EditText:

android:importantForAutofill="noExcludeDescendants"

like image 26
Gaurav Singh Avatar answered Nov 12 '22 21:11

Gaurav Singh


Luke Simpson almost make it right, just should use "styles.xml" instead of "themes.xml".

I created a new style file with version qualifier, aiming to v26, to make it clearer.
Just copy and paste your AppTheme for the v26/styles.xml and add editTextStyle items the EditTextStyle style.

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    ...
    <item name="android:editTextStyle">@style/App_EditTextStyle</item>
    <item name="editTextStyle">@style/App_EditTextStyle</item>
</style>

<style name="App_EditTextStyle" parent="@android:style/Widget.EditText">
    <item name="android:importantForAutofill">noExcludeDescendants</item>
</style>

In this way you make this changes for all your EditTexts without needing to change your layout files.

like image 12
Endy Silveira Avatar answered Nov 12 '22 19:11

Endy Silveira