如何在android中获取资源字符串数组?

时间:2013-10-18 09:36:52

标签: java android resources android-xml android-resources

我有超过10000个城市名称,我想在ListView中显示。我将这些名称存储为res/values folder

中的city.xml文件

如下所示

<resources>
<string-array name="city"> 
<item>  chennai, India </item>
<item>  Spring Creek , Australia </item>
.
.

然后我创建一个ArrayAdapter并像这样填充listView。

String[] cityDetails = res.getStringArray(R.array.city); // <-- getting Error in this line
myAdapter = new ArrayAdapter<String>(this, R.layout.ap_details_row, R.id.aNameTV, cityDetails );
myLV.setAdapter(myAdapter);

它在API 13级及以上设备中运行良好。但是在API级别13设备之下,我收到以下错误。

 W/dalvikvm(306): ReferenceTable overflow (max=512)
 W/dalvikvm(306): Last 10 entries in JNI local reference table:
  W/dalvikvm(306):   502: 0x45fbb330 cls=Ljava/lang/String; (28 bytes)
  W/dalvikvm(306):   503: 0x45fbb388 cls=Ljava/lang/String; (28 bytes)
  W/dalvikvm(306):   504: 0x45fbb3e0 cls=Ljava/lang/String; (28 bytes)
  W/dalvikvm(306):   505: 0x45fbb438 cls=Ljava/lang/String; (28 bytes)
  W/dalvikvm(306):   506: 0x45fbb498 cls=Ljava/lang/String; (28 bytes)
  W/dalvikvm(306):   507: 0x45fbb4f8 cls=Ljava/lang/String; (28 bytes)
  W/dalvikvm(306):   508: 0x45fbb558 cls=Ljava/lang/String; (28 bytes)
  W/dalvikvm(306):   509: 0x45fbb5d0 cls=Ljava/lang/String; (28 bytes)
  W/dalvikvm(306):   510: 0x45fbb638 cls=Ljava/lang/String; (28 bytes)
  W/dalvikvm(306):   511: 0x45fbb698 cls=Ljava/lang/String; (28 bytes)
  W/dalvikvm(306): JNI local reference table summary (512 entries):
  W/dalvikvm(306):     3 of Ljava/lang/Class; 164B (2 unique)
  W/dalvikvm(306):   507 of Ljava/lang/String; 28B (507 unique)
  W/dalvikvm(306):     1 of [Ljava/lang/String; 28B
  W/dalvikvm(306):     1 of [Ljava/lang/String; 37436B
  W/dalvikvm(306): Memory held directly by tracked refs is 51988 bytes
  E/dalvikvm(306): Failed adding to JNI local ref table (has 512 entries)
  I/dalvikvm(306): "main" prio=5 tid=1 RUNNABLE
  I/dalvikvm(306):   | group="main" sCount=0 dsCount=0 s=N obj=0x4001d8e0 self=0xccb0
  I/dalvikvm(306):   | sysTid=306 nice=0 sched=0/0 cgrp=default handle=-1345026008
  I/dalvikvm(306):   | schedstat=( 1050455605 562911400 652 )
  I/dalvikvm(306):   at android.content.res.AssetManager.getArrayStringResource(Native Method)
  I/dalvikvm(306):   at android.content.res.AssetManager.getResourceStringArray(AssetManager.java:186)
  I/dalvikvm(306):   at android.content.res.Resources.getStringArray(Resources.java:381)
  I/dalvikvm(306):   at com.mypro.main.HomeActivity.onCreate(HomeActivity.java:184)
 I/dalvikvm(306):   at dalvik.system.NativeStart.main(Native Method)
 E/dalvikvm(306): VM aborting

任何帮助都将不胜感激。

0 个答案:

没有答案