Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Else statement inside Switch is an syntax error?

I am getting Syntax Error on the else statement in the following code :

switch(v.getId())
{
case R.id.b0 :      
    if(s.length()==1 && s.charAt(0)=='0');
    {  
    et2.setText("0");
    et1.setText("0");
    }
    else
    {
    s=s+"0";
    call(s);
    }
    break;
//2nd case and body
}

The Error is : Syntax error on token "else", delete this token

Does java not permit this?

Will I have to use the nested switch?

Or is there something wrong with my code itself?

like image 543
Exorcist Avatar asked May 26 '26 14:05

Exorcist


2 Answers

if(s.length()==1 && s.charAt(0)=='0');

remove ;

like image 68
Eng.Fouad Avatar answered May 30 '26 02:05

Eng.Fouad


if(s.length()==1 && s.charAt(0)=='0');
                                     ^ Remove this!

You're terminating your if statement earlier than you think you are...

like image 25
Mat Avatar answered May 30 '26 04:05

Mat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!