注意:这是android系统的具体问题,不是简单的超出界限的异常,有些暗示重复
我在调查异常原因时遇到问题。 我正在尝试获取字符串资源文本(HTML):
val string = getString(R.string.long_html_text)
此HTML当然有效(适用于模拟器和其他实际设备),但不适用于真实设备LGE Nexus 5X API 27。 html文本有40113个字符。
当我尝试获取上述字符串资源时,我得到了这个例外:
04-17 14:38:17.136 2847-2847/com.myapp.tmt.app.myapp E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.myapp.tmt.app.myapp, PID: 2847
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapp.tmt.app.myapp/com.myapp.tmt.app.myapp.ui.eula.EulaActivity}: java.lang.IndexOutOfBoundsException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2778)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: java.lang.IndexOutOfBoundsException
at android.content.res.StringBlock.nativeGetString(Native Method)
at android.content.res.StringBlock.get(StringBlock.java:82)
at android.content.res.AssetManager.getResourceValue(AssetManager.java:236)
at android.content.res.AssetManager.getResourceText(AssetManager.java:164)
at android.content.res.Resources.getText(Resources.java:335)
at android.content.res.Resources.getString(Resources.java:433)
at android.content.Context.getString(Context.java:556)
at com.myapp.tmt.app.myapp.ui.eula.EulaActivity.prepareLicence(EulaActivity.kt:33)
at com.myapp.tmt.app.myapp.ui.eula.EulaActivity.onCreate(EulaActivity.kt:28)
at android.app.Activity.performCreate(Activity.java:6999)
at android.app.Activity.performCreate(Activity.java:6990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
有没有人遇到过它?
答案 0 :(得分:3)
由于这只发生在Android Oreo设备上,我只能通过将非常长的HTML字符串拆分为两部分来解决此问题。
我认为此问题是由于新的Android安全限制(正如此处所建议的那样)