This is my code:
boolean startGameBoolean;
Bundle extras = getIntent().getExtras();
extras.getInt(\"startGameBoolean\");
if (startGameBoolean = true){
counte
I had this same problem developing for Android.
The reason you're seeing those warnings saying the "variable is never read" is because you're assigning it RIGHT AFTER creating it. Try creating the variable at the start of the class, then assigning it in an OnCreate() or other appropriate method that gets called when the class is first created.
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.
I would venture to agree with Eclipse, it's not being used. The code you've show us doesn't have it being used anywhere.
Update
The variable is still never used because you assign it in your if
condition; you never compare it (which is what it looks like you're trying to do).
Change
if (startGameBoolean = true){
to
if (startGameBoolean){
Bundle extras = getIntent().getExtras();
boolean startGameBoolean = extras.getBoolean("startGameBoolean");
Something like this? You cant fetch boolean
with getInt()
. Perhaps, if you are dealing with int but with values 0
and 1
. Then you should change the type of startGameBoolean
to int
and fetch it with getInt()
, people do this sometimes.
if (startGameBoolean = true){
Should be..
if (startGameBoolean == true){
..or better still..
if (startGameBoolean){
I had a similar error... for this line
JLabel label = new JLabel("You have $" + amountInAccount + " in your account.");
I used Quick fix (Ctrl+1) and chose Remove 'label', keep side-effect assignments...
and the code became
new JLabel("You have $" + amountInAccount + " in your account.");