2011-10-06 27 views
0

Eclispe編譯器向我展示了我的else else if語句上的錯誤sntax。誰能告訴我什麼是錯的?謝謝!Android:編譯我的if else語句時出錯

代碼

//click on one of chapters 
    list.setOnItemClickListener(new OnItemClickListener() 
    { 
     public void onItemClick(AdapterView<?> parent, View view, int position, long id) 
     { 

      String item = ((TextView)view).getText().toString(); 

      Toast.makeText(getBaseContext(), item, Toast.LENGTH_LONG).show(); 

      //Choose Chapter 1 
      if (item.equalsIgnoreCase("I. The Global Business Environment")); { 
      //go to chapter 1 
      startActivity(new Intent(ChaptersActivity.this, Chapter1Activity.class)); 
      } else if (item.equalsIgnoreCase("II. Information Systems")); { 
       //go to chapter 2 
       startActivity(new Intent(ChaptersActivity.this, Chapter2Activity.class)); 
      } 

      //Choose Chapter 3 
      else if (item.equalsIgnoreCase("III. Operations Management")); 
      { 
       //go to chapter 3 
       startActivity(new Intent(ChaptersActivity.this, Chapter3Activity.class)); 
      } 

      //Choose Chapter 4 
      else if (item.equalsIgnoreCase("IV. Marketing")); 
      { 
       //go to chapter 4 
       startActivity(new Intent(ChaptersActivity.this, Chapter4Activity.class)); 
      } 

      //Choose Chapter 5 
      else if (item.equalsIgnoreCase("V. Managing Human Capital")); 
      { 
       //go to chapter 5 
       startActivity(new Intent(ChaptersActivity.this, Chapter5Activity.class)); 
      } 

      //Choose Chapter 6 
      else if (item.equalsIgnoreCase("VI. Preparing for the Examination")); 
      { 
       //go to chapter 6 
       startActivity(new Intent(ChaptersActivity.this, Chapter6Activity.class)); 
      } 
     } 
    }); 

它們顯示在 '其他' 代碼的話,任何想法錯誤sntax?

+0

更好的方法是在視圖上使用id屬性,然後調用view.getId()並放入switch語句中。 – Merlin

回答

4

你在你的,如果條件到底有semicolon

if (item.equalsIgnoreCase("I. The Global Business Environment")); { 

即結束,如果語句中,{開始一個新的塊,然後其他人顯示了無章可循。

+0

謝謝!找到答案 – user975057

0

;顯示在每條if-else條件聲明中。你最好將它們移出並嘗試再次構建它:)