問題描述
將我們的一些設(shè)備更新到 android 8.0 后,在關(guān)注 TextInputLayout
內(nèi)的 TextInputEditText
字段時(shí),應(yīng)用程序崩潰并出現(xiàn)此 Exception
:
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)
當(dāng)我們進(jìn)入 android 設(shè)置 -> 系統(tǒng) -> 語言 &輸入 -> 高級 -> 自動(dòng)填充服務(wù) -> 無 ,然后專注于 TextInputEditText
/
TextInputLayout
不再崩潰.
When we go to android Settings -> System -> Languages & input -> Advanced -> Auto-fill service -> None , then focusing on the TextInputEditText
/
TextInputLayout
no longer crashes.
我們?nèi)绾卧诓唤迷O(shè)備上新的 8.0 自動(dòng)填充服務(wù)的情況下防止崩潰發(fā)生?
推薦答案
我也遇到了.事實(shí)證明,問題是由嵌套在 TextInputLayout
內(nèi)的 EditText
上設(shè)置提示文本引起的.
I ran into this too. It turns out the issue was caused by setting the hint text on the EditText
nested inside the TextInputLayout
.
我進(jìn)行了一些挖掘,并在 26.0.0 Beta 2 發(fā)行說明中找到了這個(gè)塊.2017 年 6 月 Android 支持版本說明
I did some digging and found this nugget in the 26.0.0 Beta 2 release notes. Android Support Release Notes June 2017
TextInputLayout 必須在 onProvideAutofillStructure() 上設(shè)置提示
TextInputLayout must set hints on onProvideAutofillStructure()
這導(dǎo)致我嘗試在 TextInputLayout
而不是嵌套的 EditText
上設(shè)置提示.
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>
我將此作為答案發(fā)布在這里 因?yàn)槲野褧炁炝?很抱歉兩次發(fā)布相同的答案.
I posted this as an answer here as I mixed up bookmarks. Sorry for posting the same answer twice.
這篇關(guān)于Android 8.0 Oreo 在聚焦 TextInputEditText 時(shí)崩潰的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!