英文:
NullPointerException in TextInputLayout on Xiaomi with Android 10
问题
最近我在我的安卓应用中开始使用 TextInputLayout
。之后,奇怪的 NullPointerException
错误开始出现。这些错误只在搭载 Android 10
的 小米(Xiaomi)
设备上发生。
致命异常: java.lang.NullPointerException
尝试调用空对象引用上的直接方法 'void android.widget.Editor$SelectionModifierCursorController.initDrawables()'
android.widget.Editor$SelectionModifierCursorController.access$300
没有办法重现这个错误(我没有小米设备)。在搜索互联网时,我意识到这个错误发生在尝试在 TextInputLayout
字段中输入电子邮件时。
互联网上有React Native的解决方案:https://github.com/facebook/react-native/issues/27204
不幸的是,我还没有找到Java的解决方案。
来自Crashlytics的截图:
完整报告:
android.widget.Editor$SelectionModifierCursorController.access$300 (Editor.java:6709)
android.widget.Editor.getEmailPopupWindow (Editor.java:1471)
android.widget.Editor.showEmailPopupWindow (Editor.java:1479)
android.widget.Editor.handleEmailPopup (Editor.java:1458)
android.widget.Editor.updateCursorPosition (Editor.java:2101)
android.widget.TextView.getUpdatedHighlightPath (TextView.java:7823)
android.widget.TextView.onDraw (TextView.java:8008)
android.view.View.draw (View.java:21594)
android.view.View.updateDisplayListIfDirty (View.java:20437)
android.view.ViewGroup.recreateChildDisplayList (ViewGroup.java:4456)
android.view.ViewGroup.dispatchGetDisplayList (ViewGroup.java:4429)
android.view.View.updateDisplayListIfDirty (View.java:20388)
android.view.View.draw (View.java:21312)
android.view.ViewGroup.drawChild (ViewGroup.java:4472)
android.view.ViewGroup.dispatchDraw (ViewGroup.java:4231)
android.view.View.draw (View.java:21601)
com.google.android.material.textfield.TextInputLayout.draw (TextInputLayout.java:3064)
android.view.View.updateDisplayListIfDirty (View.java:20437)
android.view.ViewGroup.recreateChildDisplayList (ViewGroup.java:4456)
android.view.ViewGroup.dispatchGetDisplayList (ViewGroup.java:4429)
android.view.View.updateDisplayListIfDirty (View.java:20388)
android.view.ViewGroup.recreateChildDisplayList (ViewGroup.java:4456)
android.view.ViewGroup.dispatchGetDisplayList (ViewGroup.java:4429)
android.view.View.updateDisplayListIfDirty (View.java:20388)
android.view.ViewGroup.recreateChildDisplayList (ViewGroup.java:4456)
android.view.ViewGroup.dispatchGetDisplayList (ViewGroup.java:4429)
android.view.View.updateDisplayListIfDirty (View.java:20388)
android.view.ViewGroup.recreateChildDisplayList (ViewGroup.java:4456)
android.view.ViewGroup.dispatchGetDisplayList (ViewGroup.java:4429)
android.view.View.updateDisplayListIfDirty (View.java:20388)
android.view.ViewGroup.recreateChildDisplayList (ViewGroup.java:4456)
android.view.ViewGroup.dispatchGetDisplayList (ViewGroup.java:4429)
android.view.View.updateDisplayListIfDirty (View.java:20388)
android.view.ViewGroup.recreateChildDisplayList (ViewGroup.java:4456)
android.view.ViewGroup.dispatchGetDisplayList (ViewGroup.java:4429)
android.view.View.updateDisplayListIfDirty (View.java:20388)
android.view.ViewGroup.recreateChildDisplayList (ViewGroup.java:4456)
android.view.ViewGroup.dispatchGetDisplayList (ViewGroup.java:4429)
android.view.View.updateDisplayListIfDirty (View.java:20388)
android.view.ViewGroup.recreateChildDisplayList (ViewGroup.java:4456)
android.view.ViewGroup.dispatchGetDisplayList (ViewGroup.java:4429)
android.view.View.updateDisplayListIfDirty (View.java:20388)
android.view.ThreadedRenderer.updateViewTreeDisplayList (ThreadedRenderer.java:575)
android.view.ThreadedRenderer.updateRootDisplayList (ThreadedRenderer.java:581)
android.view.ThreadedRenderer.draw (ThreadedRenderer.java:654)
android.view.ViewRootImpl.draw (ViewRootImpl.java:3844)
android.view.ViewRootImpl.performDraw (ViewRootImpl.java:3635)
android.view.ViewRootImpl.performTraversals (ViewRootImpl.java:2955)
android.view.ViewRootImpl.doTraversal (ViewRootImpl.java:1865)
android.view.ViewRootImpl$TraversalRunnable.run (ViewRootImpl.java:8029)
android.view.Choreographer$CallbackRecord.run (Choreographer.java:969)
android.view.Choreographer.doCallbacks (Choreographer.java:793)
android.view.Choreographer.doFrame (Choreographer.java:728)
android.view.Choreographer$FrameDisplayEventReceiver.run (Choreographer.java:954)
android.os.Handler.handleCallback (Handler.java:883)
android.os.Handler.dispatchMessage (Handler.java:100)
android.os.Looper.loop (Looper.java:224)
android.app.ActivityThread.main (ActivityThread.java:7509)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:539)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:995)
英文:
I recently started using TextInputLayout
in my android app. After that, strange NullPointerException
errors started to appear. These errors only occur on Xiaomi
devices with Androind 10
.
Fatal Exception: java.lang.NullPointerException
Attempt to invoke direct method 'void android.widget.Editor$SelectionModifierCursorController.initDrawables()' on a null object reference
android.widget.Editor$SelectionModifierCursorController.access$300
There is no way to reproduce the error (I do not have a Xiaomi device). Searching the Internet realized that this error occurs when trying to enter email in the TextInputLayout
field.
There is a solution for React Native on the internet: https://github.com/facebook/react-native/issues/27204
Unfortunately, I have not been able to find a solution for Java.
Screenshot from Crashlytics:
Full report:
android.widget.Editor$SelectionModifierCursorController.access$300 (Editor.java:6709)
android.widget.Editor.getEmailPopupWindow (Editor.java:1471)
android.widget.Editor.showEmailPopupWindow (Editor.java:1479)
android.widget.Editor.handleEmailPopup (Editor.java:1458)
android.widget.Editor.updateCursorPosition (Editor.java:2101)
android.widget.TextView.getUpdatedHighlightPath (TextView.java:7823)
android.widget.TextView.onDraw (TextView.java:8008)
android.view.View.draw (View.java:21594)
android.view.View.updateDisplayListIfDirty (View.java:20437)
android.view.ViewGroup.recreateChildDisplayList (ViewGroup.java:4456)
android.view.ViewGroup.dispatchGetDisplayList (ViewGroup.java:4429)
android.view.View.updateDisplayListIfDirty (View.java:20388)
android.view.View.draw (View.java:21312)
android.view.ViewGroup.drawChild (ViewGroup.java:4472)
android.view.ViewGroup.dispatchDraw (ViewGroup.java:4231)
android.view.View.draw (View.java:21601)
com.google.android.material.textfield.TextInputLayout.draw (TextInputLayout.java:3064)
android.view.View.updateDisplayListIfDirty (View.java:20437)
android.view.ViewGroup.recreateChildDisplayList (ViewGroup.java:4456)
android.view.ViewGroup.dispatchGetDisplayList (ViewGroup.java:4429)
android.view.View.updateDisplayListIfDirty (View.java:20388)
android.view.ViewGroup.recreateChildDisplayList (ViewGroup.java:4456)
android.view.ViewGroup.dispatchGetDisplayList (ViewGroup.java:4429)
android.view.View.updateDisplayListIfDirty (View.java:20388)
android.view.ViewGroup.recreateChildDisplayList (ViewGroup.java:4456)
android.view.ViewGroup.dispatchGetDisplayList (ViewGroup.java:4429)
android.view.View.updateDisplayListIfDirty (View.java:20388)
android.view.ViewGroup.recreateChildDisplayList (ViewGroup.java:4456)
android.view.ViewGroup.dispatchGetDisplayList (ViewGroup.java:4429)
android.view.View.updateDisplayListIfDirty (View.java:20388)
android.view.ViewGroup.recreateChildDisplayList (ViewGroup.java:4456)
android.view.ViewGroup.dispatchGetDisplayList (ViewGroup.java:4429)
android.view.View.updateDisplayListIfDirty (View.java:20388)
android.view.ViewGroup.recreateChildDisplayList (ViewGroup.java:4456)
android.view.ViewGroup.dispatchGetDisplayList (ViewGroup.java:4429)
android.view.View.updateDisplayListIfDirty (View.java:20388)
android.view.ViewGroup.recreateChildDisplayList (ViewGroup.java:4456)
android.view.ViewGroup.dispatchGetDisplayList (ViewGroup.java:4429)
android.view.View.updateDisplayListIfDirty (View.java:20388)
android.view.ThreadedRenderer.updateViewTreeDisplayList (ThreadedRenderer.java:575)
android.view.ThreadedRenderer.updateRootDisplayList (ThreadedRenderer.java:581)
android.view.ThreadedRenderer.draw (ThreadedRenderer.java:654)
android.view.ViewRootImpl.draw (ViewRootImpl.java:3844)
android.view.ViewRootImpl.performDraw (ViewRootImpl.java:3635)
android.view.ViewRootImpl.performTraversals (ViewRootImpl.java:2955)
android.view.ViewRootImpl.doTraversal (ViewRootImpl.java:1865)
android.view.ViewRootImpl$TraversalRunnable.run (ViewRootImpl.java:8029)
android.view.Choreographer$CallbackRecord.run (Choreographer.java:969)
android.view.Choreographer.doCallbacks (Choreographer.java:793)
android.view.Choreographer.doFrame (Choreographer.java:728)
android.view.Choreographer$FrameDisplayEventReceiver.run (Choreographer.java:954)
android.os.Handler.handleCallback (Handler.java:883)
android.os.Handler.dispatchMessage (Handler.java:100)
android.os.Looper.loop (Looper.java:224)
android.app.ActivityThread.main (ActivityThread.java:7509)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:539)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:995)
答案1
得分: 1
以下是我为了解决崩溃问题所做的操作。它将在编辑电子邮件地址时禁用光标,但不会导致崩溃。
if (android.os.Build.MANUFACTURER.equals("Xiaomi", ignoreCase = true) &&
android.os.Build.VERSION.SDK_INT == android.os.Build.VERSION_CODES.Q) {
editText.isCursorVisible = false;
}
英文:
This is what I did to fix the crash. It will disable the cursor when editing an email address, but it will not crash.
if (android.os.Build.MANUFACTURER.equals("Xiaomi", ignoreCase = true) &&
android.os.Build.VERSION.SDK_INT == android.os.Build.VERSION_CODES.Q) {
editText.isCursorVisible = false
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论