资源getString的Android IndexOutOfBound异常 [英] Android IndexOutOfBound Exception for resource getString

查看:77
本文介绍了资源getString的Android IndexOutOfBound异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

注意:这是android系统的特定问题,不仅仅是一些建议重复的异常异常

Note: This is specific problem with android system, not simply out of bound exception which some suggesting duplicate

我在调查异常原因时遇到问题. 我正在尝试获取字符串资源文本(HTML):

I have a problem with investigating the cause of the exception. I'm trying to get string resource text(which is HTML):

val string = getString(R.string.long_html_text)

此HTML当然是有效的(在模拟器和其他实际设备上有效),但在实际设备LGE Nexus 5X API 27上无效. html文本包含40113个字符.

This HTML is of course valid(works on emulator and other real devices) but not on real device LGE Nexus 5X API 27. The html text has 40113 characters.

当我尝试如上所述获取此字符串资源时,出现此异常:

When I am trying to get this string resource as above I am getting this Exception:

   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) 

有人遇到吗?

推荐答案

由于这仅发生在Android Oreo设备上,因此我只能通过将很长的HTML字符串分成两部分来解决此问题.

As this was only happening on Android Oreo devices i resolve this issue only by split my very long HTML string to two parts.

我认为此问题是由于新的Android安全限制(如此处所建议)

I think that this issue was due to new Android security restrictions (as some suggested here)

这篇关于资源getString的Android IndexOutOfBound异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆