How to correct what is red?

Asked

Viewed 434 times

-3

I’m beginner and I’m not able to fix what’s in red in the image when I changed the code changed color but in Android Studio like this https://i.stack.Imgur.com/SCAR6.jpg

public class MainActivity extends Activity {                                 

    private ViewManager l;                                                   

    @Override                                                                
    protected void onCreate(Bundle savedInstanceState) {                     
        super.onCreate(savedInstanceState);                                  
        setContentView(R.layout.activity_main);                              


        String s = "";                                                       
        for (int i = 1; i <= 45; i +=6) {                                    
            TextView t = new TextView(this);                                 
            t.setText(s);                                                    
            l.addView(t);                                                    
        }                                                                    
        int x = 2;                                                           
        do {                                                                 
            Button b = new Button(this);                                     
            b.setText(x);                                                    
            l.addView(b);                                                    
            if (x == 7 && x == 13 && x == 19)                                
                continue;                                                    
        } while (x <= 24);                                                   


    }                                                                        
}                                                                            
  • Sandra, please replace your image with the written code, so anyone who wants to help you, can copy your code to analyze it more easily.

1 answer

1

It turned red because it doesn’t have as the variable x have the 3 values at the same time, you are using the operator &&:

if (x == 7 && x == 13 && x == 19)

It would be like saying x has to be equal to 7, 13 and 19 at the same time, it is as if the IDE was giving you a hint that you’ll never be able to get into that if.

I believe you wish to be the "OR", variable x has either 7 or 13 or 19, if that’s how it is:

if (x == 7 || x == 13 || x == 19)

Learn the difference of operators in https://docs.oracle.com/javase/tutorial/java/nutsandbolts/operators.html

Type Operators
Suffixals expr++ expr--
Prefixals ++expr --expr +expr -expr ~ !
Multiplicative * / %
Additives + -
Binary Shift << >> >>>
Comparative < > <= >= instanceof
equality == !=
Bit-Abit E &
Bit-Abit XOU OR ^
Bit-Abit OR |
Logical AND &&
LOGICAL OR ||
Ternary ? :
Attribution = += -= *= /= %= &= ^= |= <<= >>= >>>=

Browser other questions tagged

You are not signed in. Login or sign up in order to post.