Skip to content Skip to sidebar Skip to footer

Error: Final Local Variable Score Cannot Be Assigned, Since It Is Defined In An Enclosing Type?

I am trying to use the getIntent value(score) which is retrieve from the previous activity but it seems like it is impossible. It seems that addition and subtraction under if else

Solution 1:

Move int score to be a global variable to access it in onClick. You'll also need to remove the final keyword so the value can be changed after you initialize it.

publicclassYourActivityextendsActivity{

       int score;

      publiconCreate( /*...etc.*/

Solution 2:

Simply remove final keyword from :

finalint score = intent.getIntExtra("int", -1);

Because a final variable can only be initialized once, either via an initializer or an assignment statement.

Read more here.

Post a Comment for "Error: Final Local Variable Score Cannot Be Assigned, Since It Is Defined In An Enclosing Type?"