I am so close to getting this project to work, but I’m stuck on one thing that is driving me crazy and I can’t find anything in my research that is working.
What I need to do is declare a new variable each time the for loop passes through the recordset, but I need to use the index value (i) in the variable name.
The line I need help with is Bottles o[i] = new Bottles();
I need to define a new variable each time the for loop passes through again, for example, my variables should end up being o1, o2, o3, etc. I’m getting a syntax error on the [i] right now and I can’t seem to find out how to do this.
Any thoughts on what I’m missing here?
private void getBottles() {
try {
m_bottles = new ArrayList<Bottles>();
for (int i = 0; i < bottleNamesMap.size(); i++) {
Bottles o[i] = new Bottles();
o[i].setbottleID(bottleIntMap.get("bottleID" + i));
o[i].setname_abbr(bottleNamesMap.get("name" + i));
o[i].setorigin(bottleNamesMap.get("origin" + i));
o[i].setbottlePicture(bottleNamesMap.get("bottlePicture" + i));
o[i].setprice_reported(bottleNamesMap.get("price" + i));
o[i].setdistillery(bottleNamesMap.get("distillery" + i));
o[i].setagg_score(bottleIntMap.get("aggscore" + i));
m_bottles.add(o[i]);
Thread.sleep(2000);
Log.i("ARRAY", "" + m_bottles.size());
}
} catch (Exception e) {
Log.e("BACKGROUND_PROC", e.getMessage());
}
runOnUiThread(returnRes);
}
should be:
Then drop the
[i]. The new keyword will create a new object each iteration.