The local variable xxx is never read

后端 未结 6 1619
不思量自难忘°
不思量自难忘° 2021-01-29 13:24

This is my code:

boolean startGameBoolean;
Bundle extras = getIntent().getExtras();
extras.getInt(\"startGameBoolean\");
if (startGameBoolean = true){
    counte         


        
6条回答
  •  醉梦人生
    2021-01-29 13:44

    Shouldn't it be startGameBoolean = extras.getBoolean("startGameBoolean");?

    in the code you gave, boolean startGameBoolean; is not used anywhere. the warning means that although you declared it, it is not used in the block where it lives, therefore could (should) be removed.

    Edit:

    After seeing your addition, you use startGameBoolean, but you assign to it, while you should compare to it:

    if (startGameBoolean == true){
    //                    ^
        counter.start();
    }
    

    Also, assign the result of getBoolean() to the variable as I wrote in the first statement.

提交回复
热议问题