永远不会读取局部变量xxx [英] The local variable xxx is never read
问题描述
这是我的代码:
boolean startGameBoolean;
Bundle extras = getIntent().getExtras();
extras.getInt("startGameBoolean");
if (startGameBoolean = true){
counter.start();
}
Eclipse发出警告:永远不会读取局部变量startGameBoolean;但它是。
我从另一个意图中得到布尔值。
Eclipse gives a warning that "The local variable startGameBoolean is never read"; but it is. I get the boolean from an another intent.
我编辑了我的代码,我错过了一些,抱歉!
推荐答案
不应该是 startGameBoolean = extras.getBoolean(startGameBoolean); $ c $您提供的代码中的c>?
, boolean 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.
编辑:
看到你的添加后,你使用 startGameBoolean
,但你分配给它,你应该比较它:
After seeing your addition, you use startGameBoolean
, but you assign to it, while you should compare to it:
if (startGameBoolean == true){
// ^
counter.start();
}
此外,分配的结果getBoolean()
到我在第一个语句中写的变量。
Also, assign the result of getBoolean()
to the variable as I wrote in the first statement.
这篇关于永远不会读取局部变量xxx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!