I needed to change the variables inside the inner class, and I got the notorious error "I can’t refer to a non-finite variable inside the inner class defined by another method."
void onStart(){ bt.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { int q = i; } }); }
I quickly created a class that had everything I wanted to change, and made the final version of the class outside the inner class
class temp{ int q; } void onStart(){ final temp x = new temp(); bt.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { xq = i; } }); }
This seems to be what I need and it works, but I am wondering if this is the right solution to the problem. Also, I really hate using the word temp to mean my class. Is there a real programming term for what I did to make a more descriptive name for my class?
java inner-classes final local-variables
Aaron greenberg
source share