我的应用程序中发生的事情是我从数据库中获取了一个列,这会起作用,因为当我 System.out.println() 它以数组列表格式准确显示我想要的内容时,我尝试将其传递给另一个类并我不断收到错误消息。有谁知道为什么会这样?如果你能显示代码,请提前谢谢你。
我的主要课程的代码(很长,所以只链接一小部分):
//Declarations at the top
ArrayList<String> roles = new ArrayList<String>();
AFragmentTabDB aFDB;
DataBaseHelper myDB;
//Trying to pass the arraylist to another class called aFDB
roles = myDB.getTableColumn("role", new String[] {"name"});
System.out.println(roles);
aFDB.setRoleList(roles);
这是我试图将其传递给的课程:
public class AFragmentTabDB {
ArrayList<String> roles = new ArrayList<String>();
public void setRoleList(ArrayList<String> aL){
this.roles = aL;
}
public ArrayList<String> getRoleList(){
return roles;
}
}
这是我的 getTableColumn() 所在的位置:
public class DataBaseHelper extends SQLiteOpenHelper{
public ArrayList<String> getTableColumn(String tableName, String[] column){
ArrayList<String> aL = new ArrayList<String>();
cursor = myDataBase.query(tableName, column, null, null, null, null, null);
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
aL.add(cursor.getString(0));
cursor.moveToNext();
}
cursor.close();
return aL;
}
}