報錯信息提取
Android - Attempt to invoke virtual method 'void android.view.View.getBoundsOnScreen(android.graphics.Rect)' on a null object reference
整體崩潰信息
FATAL EXCEPTION: main
Process: br.com.fornaro.armariovirtual, PID: 5540
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.<init>(AssistStructure.java:484)
at android.app.assist.AssistStructure.<init>(AssistStructure.java:1908)
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(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
解決方案
這是Android framework 的 bug壤圃。那么我們直接說解決方案吧
- 在每個
EidtText
里添加如下屬性,但這個屬性最低要求 API=26.
android:importantForAutofill="noExcludeDescendants"
- 將
EidtText
中的hint 移到TextInputLayout
深碱∷螅可能出現(xiàn)AndroidStudio 無法預(yù)覽控件的hint
瞎领。