2012-03-30 73 views
2

我得到语法错误的else语句下面的代码:Switch中的其他语句是语法错误?

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 
} 

的错误是:Syntax error on token "else", delete this token

难道Java的不允许这样做?

我必须使用嵌套开关吗?

或者我的代码本身有问题吗?

回答

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

删除;

+0

糟糕!这是俯视简单的事情的高度。谢谢! – Exorcist 2012-03-30 16:30:23

+0

我没有想到能得到这个答案的好答案徽章:) – 2012-03-30 16:59:28

+0

haha​​ha:D ..但是你的回答非常快,不是吗? ;) – Exorcist 2012-03-30 17:10:26

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

你比你早以为你是终止您if声明...

4

删除;在如果

到底应该是:

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