Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android IndexOutOfBound Exception for resource getString

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

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)

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) 

Has anyone encounter it?

like image 472
K.Os Avatar asked Apr 17 '18 12:04

K.Os


1 Answers

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

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

like image 198
K.Os Avatar answered Nov 11 '22 12:11

K.Os