[英]JNI local reference table summary (512 entries)
I have more than 10000 city names and i want to show in ListView. 我有超过10000个城市名称,我想在ListView中显示。 I stored those names as city.xml file in res/values folder
我将这些名称存储为res/values folder
city.xml文件
like below 如下
<resources>
<string-array name="city">
<item> chennai, India </item>
<item> Spring Creek , Australia </item>
.
.
Then I create a ArrayAdapter and populate to listView like this. 然后我创建一个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);
It works fine in API level 13 and above devices. 它在API 13级及以上设备中运行良好。 But below API level 13 devices, I get the following error. 但是在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
Any help would be appreciated. 任何帮助,将不胜感激。
A few ideas: 一些想法:
1- Display data one page at a time. 1-一次显示一页数据。 When you scroll down, load more data. 向下滚动时,请加载更多数据。
2- Scrolling through 10000 records to go to the end will take forever. 2-滚动10000条记录到最后将需要永远。 Access your data via a search form. 通过搜索表单访问您的数据。 Limit results to 100 records. 将结果限制为100条记录。
3- If the data is sorted, group items together and provide an index. 3-如果数据已排序,请将项目组合在一起并提供索引。 For example, alphabetical lists can be split into 26 subsets. 例如,字母列表可以分成26个子集。 The first page shows the alphabet, and you have to click on a letter to go to a subset. 第一页显示字母表,您必须单击一个字母才能转到子集。
最好的方法是使用Base Adapter ...它懒得加载~~~
我认为你必须使用“ AutoCompleteText
”而不是“ ListView
”,因为最终用户很容易从更多数据中找到城市。
It is not good practice to show listview with 10 000 city names. 以10000个城市名称显示listview 不是一个好习惯 。 You should consider using another approach. 你应该考虑使用另一种方法。
For example, take look at AutoCompleteTextView . 例如,看看AutoCompleteTextView 。
Another thought would be to insert these values into a sqlite database and access them using a CursorLoader. 另一个想法是将这些值插入sqlite数据库并使用CursorLoader访问它们。 The cursor will handle the memory management of all the data. 游标将处理所有数据的内存管理。
Here's a great tutorial on SQLite on Android: http://www.vogella.com/articles/AndroidSQLite/article.html 这是关于Android上SQLite的一个很棒的教程: http : //www.vogella.com/articles/AndroidSQLite/article.html
Following method worked fine in all API levels. 以下方法在所有API级别都运行良好。
ArrayList<String> namelist = null;
try {
AssetManager am = activity.getAssets();
InputStream is = am.open("city_name_list.txt");
Scanner inStream = new Scanner(is);
namelist = new ArrayList<String>();
while(inStream.hasNextLine()){
namelist.add(inStream.nextLine());
}
} catch (IOException e) {
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.