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?
I ran into this too. It turns out the issue was caused by setting the hint text on the
EditText
nested inside theTextInputLayout
.I did some digging and found this nugget in the 26.0.0 Beta 2 release notes. Android Support Release Notes June 2017
That led me to try setting the hint on the
TextInputLayout
instead of the nestedEditText
.This resolved the crashing issue for me. Example:
I posted this as an answer here as I mixed up bookmarks. Sorry for posting the same answer twice.
You can set any value for importantForAutofill with a style or in the XML it's fix for NPE when you focus the EditText but it's not fix if your long press the EditText and you click on AutoFill. I found a Bug Report about this bug here, please add a star and share your observations in the bug report also.
Thx.
@Luke Simpson is right. You can use it in themes.XML like:-
in V26/app_styles.xml
But, I had to put empty tag also in app_styles.xml in the default folder. Otherwise, all the properties of Edit text were getting overriding by this and my edit text was not working properly. And when you put importantForAutoFill property for v26 and you want autofill to work in 8.1, you can simply put
So, autofill property works in 8.1. It will be disabled just for 8.0 as the crash is hapenning in 8.0 and it has already been fixed in 8.1.
Add below mentioned attribute in your
EditText
:android:importantForAutofill="noExcludeDescendants"
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 addeditTextStyle
items theEditTextStyle
style.In this way you make this changes for all your EditTexts without needing to change your layout files.
I used the v26/themes.xml to override the EditText style autofill only for Oreo 8.0.0:
Note that I had to apply the style inline for each EditText in my layout xml for it to take effect. I tried to apply this change globally in my app theme but it didn't work for some reason.