将我们的一些设备更新到 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模板网!
在android中剪切、复制、粘贴Cut, copy, paste in android(在android中剪切、复制、粘贴)
android EditText 融入背景android EditText blends into background(android EditText 融入背景)
更改 EditText 的线条颜色 - AndroidChange Line Color of EditText - Android(更改 EditText 的线条颜色 - Android)
EditText 始终显示带 2 位小数的数字EditText showing numbers with 2 decimals at all times(EditText 始终显示带 2 位小数的数字)
更改光标在展开的 EditText 中的开始位置Changing where cursor starts in an expanded EditText(更改光标在展开的 EditText 中的开始位置)
android中的EditText,adjustPan,ScrollView问题EditText, adjustPan, ScrollView issue in android(android中的EditText,adjustPan,ScrollView问题)