I am a beginner with both java and android. In an app I was trying to make, I was using the following for loop:
for(int current = 0; current < cityDetailsArray.size(); current++) {
row = new TableRow(this);
OnClickListener rowClickListener = new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
showDetailsView(cityDetailsArray.get(current)); //error - Cannot refer to a non-final variable current inside an inner class defined in a different method
}
};
row.setOnClickListener(rowClickListener);
//rest of the loop
}
So as shown in the comment an error popped up, the fix was to add final
to the int current
. I did just that and then this error popped up in the final int current
line:
The final local variable current cannot be assigned. It must be blank and not using a compound assignment
For which the fix is not shown, but obviously it is to remove the final
. What can I do to resolve this?