-1

我正在尝试从 SQLite-db 读取,将结果放入自定义类型容器的对象中,将容器的内容放入 ArrayList 中,我可以构建一个由 arraylist 填充的列表视图。我被困在尝试将填充的容器对象传递给 ArrayList 的点:

ArrayList<Container> myListContent = new ArrayList<Container>();
{ 
Container conSelected = db.readContainer(i);

int s1 = conSelected.getId();
Log.i("LISTE", "id = " + s1);

String s2 = conSelected.getVorname();
Log.i("LISTE", "vorname = " + s2);

String s3 = conSelected.getName();
Log.i("LISTE", "name = " + s3);

// Container to the ArrayList  
//THIS NEXT COMMAND IS TROUBLING ME. ALL THREE GIVE THE SAME LOG
//myListContent.add(conSelected);
//myListContent.add(new Container(conSelected.getId(), conSelected.getVorname(), conSelected.getName()));
//myListContent.add(new Container(conSelected));

Log.i("LISTE", "line = " + myListContent); 
}

//this.myAdapter = new ListActivity(this, R.layout.row, myListContent); 

我的 Logcat 说:

03-11 18:17:43.336: I/LISTE(7477): id = 1
03-11 18:17:43.336: I/LISTE(7477): vorname = Fred
03-11 18:17:43.336: I/LISTE(7477): name = Einsner
03-11 18:17:43.336: I/LISTE(7477): line = [null]
...
03-11 18:17:43.375: I/LISTE(7477): id = 6
03-11 18:17:43.375: I/LISTE(7477): vorname = Wolf
03-11 18:17:43.375: I/LISTE(7477): name = Sechsland
03-11 18:17:43.375: I/LISTE(7477): line = [null, null, null, null, null, null]

谁能帮我这个?我还是个菜鸟:(

4

2 回答 2

1
    ArrayList<Container> myListContent = new ArrayList<Container>();

   { 
    Container conSelected = db.readContainer(i);
    // Container to the ArrayList  
    myListContent.add(conSelected);

    Log.i("LISTE", "line = " + myListContent); 
    }
于 2013-03-11T17:43:08.643 回答
1

尽管已经选择了答案,但我还是弄清楚了错误是什么,并想把它放在这里。

如果您看一下Log.i,该方法将作为参数(字符串,字符串),因为他正在传递这一行Log.i("LISTE", "line = " + myListContent);

myListContent 遭受字符串强制转换,这导致空值。与System.out.println(myListContent)"将传递值的a 不同Content.ToString()

于 2013-03-11T18:26:28.513 回答