dude
dude

Reputation: 41

Array constants can only be used in initializers

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);
    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?

Upvotes: 3

Views: 3989

Answers (1)

Ernest Friedman-Hill
Ernest Friedman-Hill

Reputation: 81684

You just have to use slightly different syntax:

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

Upvotes: 3

Related Questions