开发者

Array constants can only be used in initializers

开发者 https://www.devze.com 2023-04-05 03:47 出处:网络
public String[] getData(){ String[] columns = {KEY_ROWID, KEY_TIME, KEY_TXT}; Object[] data; Cursor c = database.query(DB_TABLE, columns, null, null, null, null, null);
public String[] getData(){
    String[] columns = {KEY_ROWID, KEY_TIME, KEY_TXT};
    Object[] data;

    Cursor c = database.query(DB_TABLE, columns, null, null, null, null, null);
    int iRow = c.getColumnIndex(KEY_ROWID);
    int iTime = c.getColumnIndex(KEY_TIME);
    int iTxt = c.getColumnIndex(KEY_TXT);
 开发者_StackOverflow   for(c.moveToFirst(); !c.isAfterLast(); c.moveToNext()){

        data[c.getPosition()+1] = {c.getString(iRow), c.getString(iTime), c.getString(iTxt)};

    }

    return data;
}

You pretty much get the idea what I wanna do here. Can't update the data variable from for loop. But I would need to do that. How?


You just have to use slightly different syntax:

data[c.getPosition()+1] =
    new String[]{c.getString(iRow), c.getString(iTime), c.getString(iTxt)};
0

精彩评论

暂无评论...
验证码 换一张
取 消