0

When I try to get all references into array I get error. Failed adding to JNI local ref table (has 512 entries).

I try to read all strings into Array like:

String[] aStrings = mAppContext.getResources().getStringArray(R.array.a_array)

in xml i have 500+ lines of strings, like:

<string-array name="a_array">
    <item>0@100@Name1</item>
    <item>1@101@name2</item>
    ...
    ...
    ...
    <item>600@101@name600</item>
</string-array>

If i run my code in for exemple note2(4.+) everything works ok, if I run it in wildfire(2.+) I get error. If i reduce entries bellow 500 then everything works ok. I belive that error that I get is because of low memory on older device. When error happens applicatin crash.

Now I got two questions:

  1. can I avoid this error? somehow fix this? so that my app woun't crash.
  2. is there a way to catch this error and load smaller array? (I tryed with try catch block, but no success)
5er
  • 2,506
  • 7
  • 32
  • 49

1 Answers1

0

I did fix the problem. Insted of creating <string-array name="a_array"> I created:

<string name="a_array">
  0@100@Name1#
  1@101@name2#
  ...
  ...
  N@N@nameN
</string>

And than i read string into variable, and with .split("#"); parse it into array.

5er
  • 2,506
  • 7
  • 32
  • 49