发布于 4年前
Android Studio 3.1 EditText 循环调用导致:StackOverflowError: stack size 8MB
升级到Android Studio 3.1后,原来项目中一个简单的EditText都会报StackOverflowError错误。
代码如:
<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
当点击EditText,获焦时getTextBeforeCursor方法循环调用,最后导致了堆溢出异常,异常如下:
java.lang.StackOverflowError: stack size 8MB
at android.view.inputmethod.InputConnectionWrapper.getTextBeforeCursor(InputConnectionWrapper.java:46)
at android.view.inputmethod.InputConnectionWrapper.getTextBeforeCursor(InputConnectionWrapper.java:46)
at android.view.inputmethod.InputConnectionWrapper.getTextBeforeCursor(InputConnectionWrapper.java:46)
at android.view.inputmethod.InputConnectionWrapper.getTextBeforeCursor(InputConnectionWrapper.java:46)
at android.view.inputmethod.InputConnectionWrapper.getTextBeforeCursor(InputConnectionWrapper.java:46)
at android.view.inputmethod.InputConnectionWrapper.getTextBeforeCursor(InputConnectionWrapper.java:46)
at android.view.inputmethod.InputConnectionWrapper.getTextBeforeCursor(InputConnectionWrapper.java:46)
at android.view.inputmethod.InputConnectionWrapper.getTextBeforeCursor(InputConnectionWrapper.java:46)
at android.view.inputmethod.InputConnectionWrapper.getTextBeforeCursor(InputConnectionWrapper.java:46)
在Stackoverflow上有人说这是Android Studio 3.1 advanced profiling的bug:https://issuetracker.google.com/issues/76404689。
解决方法:
禁用advanced profiling:
Edit Configurations -> Profiling -> 去掉Enable advanced profiling的勾选