2012-03-30 79 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')