問題描述
將我們的一些設備更新到 android 8.0 后,在關注 TextInputLayout
內的 TextInputEditText
字段時,應用程序崩潰并出現此 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)
當我們進入 android 設置 -> 系統 -> 語言 &輸入 -> 高級 -> 自動填充服務 -> 無 ,然后專注于 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.
我們如何在不禁用設備上新的 8.0 自動填充服務的情況下防止崩潰發生?
推薦答案
我也遇到了.事實證明,問題是由嵌套在 TextInputLayout
內的 EditText
上設置提示文本引起的.
I ran into this too. It turns out the issue was caused by setting the hint text on the EditText
nested inside the TextInputLayout
.
我進行了一些挖掘,并在 26.0.0 Beta 2 發行說明中找到了這個塊.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() 上設置提示
TextInputLayout must set hints on onProvideAutofillStructure()
這導致我嘗試在 TextInputLayout
而不是嵌套的 EditText
上設置提示.
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.
這篇關于Android 8.0 Oreo 在聚焦 TextInputEditText 時崩潰的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!