在我的android項目中,我成功創建了SQLite數據庫,插入操作也成功。 我無法將列表檢索到方法中。無法從SQLIte查詢方法中檢索列表<String>
這裏是我的調用方法:
protected void getTheServerList() {
ServerManger info = new ServerManger(this);
try {
info.open();
servers = info.getData();
info.close();
} catch (Exception e) {
Toast.makeText(getApplicationContext(), "EXCEPTION !",
Toast.LENGTH_SHORT).show();
} finally {
}
}
這裏是我的SQLite方法
public List<String > getData() {
String[] columns = new String[] { KEY_ROWID, KEY_NAME, KEY_UNAME,
KEY_PASSWORD };
List<String> sItems=null;
Cursor c = ourDatabase.query(TABLE_NAME, columns, null, null, null,
null, null);
String result = "";
int iRow = c.getColumnIndex(KEY_ROWID);
int iName = c.getColumnIndex(KEY_NAME);
int iUname = c.getColumnIndex(KEY_UNAME);
int iPass = c.getColumnIndex(KEY_PASSWORD);
for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
//sItems.add(KEY_NAME);
result =c.getString(iName);
sItems.add(result);
}
c.close();
return sItems;
}
,我得到一個Exception
03-12 12:19:15.798: E/Database(390): close() was never explicitly called on database '/data/data/com.example.proj/databases/PROJ_DB'
我可以檢索的字符串,但不清單
請幫忙!
你得到空指針異常? – sandy 2013-03-12 07:21:02