java - 无法访问的代码 - 不应该无法访问

标签 java android eclipse loops arraylist

我想用从文件读取的数据填充自定义 ListView 。使用 ReadPeopleDetails 方法读取该文件。这将返回一个数组列表,然后我使用循环获取名称字符串并将其放入数组列表 people_name 中。

但是显然 final ArrayAdapter 适配器行无法访问,可能是因为 for 循环。第二双眼睛能告诉我这是为什么吗?

我认为 for 循环将结束(长度由 arraylist 的长度指定)

代码:

public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.add_party__people_list, menu);
    ArrayList<PeopleDetails> people_list = Readpeopledetails();
    ArrayList<String> people_name = null; ///this will catch the names from the above line, and put them into
    ///an arraylist for use in populating the ListView
    int i = people_list.size();
    //int j; acts as counter in iterator system
    PeopleDetails[] people_array = (PeopleDetails[]) people_list.toArray();
    for(int j = people_list.size(); /*not using termination*/ ; j++ ){
        people_name.add(people_array[j].name);

    }

    final ArrayAdapter adapter = new ArrayAdapter(this, R.layout.person_list_item, people_name);
    return true;
}

最佳答案

for(int j = people_list.size(); /*not using termination - SO LOOP WONT END*/ ; j++ ){

这从列表的末尾开始并从那里递增,因此它将永远持续下去。您可能想要...

for(int j = 0; j < i ; j++ ){

关于java - 无法访问的代码 - 不应该无法访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20870266/

相关文章:

java - 如何动态获取系统最新时区?

java - 小面 Debug模式不起作用

java - Spring JDBC for SQL Server - 使用 SQLXML 数据类型会产生 SQLServerException : Implicit conversion from data type xml to nvarchar(max) is not allowed

Java 日志记录 API 开销

android - Viewpager上的VideoView,切换页面时停止视频

android - 如何注册一个 Intent 被其他应用程序发现?

eclipse - 让 Eclipse 识别自动 CUDA 内核变量和函数

java - Eclipse动态Web项目: where should I put resource files

Android Activity 标题等待旋转

java - QNX6下如何提高Eclipse IDE的性能