KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I needed to change variables inside an inner class and I got the infamous "Cannot refer to a non-final variable inside an inner class defined in a different method" error. void onStart(){ bt.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { int q = i; } }); } I quickly made a class that held all of the things I wanted to change and made a 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) { x.q = i; } }); } This seems to be what I need and it works but I am wondering if this is how to correctly work around the problem. Also, I really hate using the word temp to name my class. Is there an actual programming term for what I did so that I make a more descriptive name for my class?
Tags (comma-separated)
Save Edits
Cancel