0

私のアンドロイド プロジェクトでは、SQLite データベースの作成に成功しました。挿入操作も成功しています。List を method に取得できません。

ここに私の呼び出し方法があります:

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' 

String は取得できますが、List は取得できません

助けてください !

4

2 に答える 2

0
public List<String > getData() {
    String[] columns = new String[] { KEY_ROWID, KEY_NAME, KEY_UNAME,
            KEY_PASSWORD };
    List<String> sItems=new ArrayList<String>  // define instance Here you create listview but not creat this instance 
    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;
}
于 2013-03-12T07:19:15.457 に答える
0

あなたのリストを開始します..リストはnull

List<String> sItems=new ArrayList<String>();
于 2013-03-12T07:18:13.297 に答える