开发者

JNI overflow when hashmap > 512

Using a resource file, I create a big hashmap

HashMap<String, String> bigHash = new HashMap<String, String>();
public void createHash(){
    String [] items = getResources().getStringArray(R.array.dual_strings);
    String [] temp;
    for ( String s : items ){
        temp = s.split("@");
        bigHash.put(temp[0],temp[1]);
    }
}

dual_string.xml is full of records like "Sleep@Better sleep more than 6 hours a day"

However, I tried with a big (~1000 items) dual_strings.xml file and app crashes immediately after starting. Looking at LogCag "dalvikvm failed adding to JNI local ref table (has 512 entrie开发者_开发知识库s)"

Is there anything I can do to create and use a big hash from my long resource file? Thanks


This looks like a bug in Android's native code for getStringArrayResources. I've found that there's a bug filed on this already. It's easy to see the cause of this in the native code (a reference is created in a loop, but not cleaned up).

http://code.google.com/p/android/issues/detail?id=5287&q=getArrayStringResource&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars

For now, you'll have to work around this bug. You'll have to split your array of strings into smaller chunks of <500 strings each, or write your own custom string array loading method. Perhaps someone else can come up with a nicer solution.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜