2011-08-05 124 views
0

這是從我的主要活動snipet的代碼,錯誤顯示,我不明白什麼是錯的?藍牙onClickView錯誤

錯誤是:void是變量onClick的無效類型。

我是新來的android和java,所以它可能會很簡單..謝謝。

private void startApp(){ 

     View Patient_Button = findViewById(R.id.patientButton); 
     Patient_Button.setOnClickListener(this); 
     View Doctor_Button = findViewById(R.id.doctorButton); 
     Doctor_Button.setOnClickListener(this); 
     View About_Option = findViewById(R.id.aboutButton); 
     About_Option.setOnClickListener(this); 
     View Exit_Option = findViewById(R.id.exit); 
     Exit_Option.setOnClickListener(this); 

Error:  public void onClick(View v) { 
      switch (v.getId()) { 
      case R.id.patientButton: 
       Intent b = new Intent(this, Detailed_ModeActivity.class); 
       startActivity(b); 
       break; 
      case R.id.doctorButton: 
       Intent a = new Intent(this, Detailed_ModeActivity.class); 
       startActivity(a); 
       break; 
      case R.id.aboutButton: 
       Intent i = new Intent(this, About.class); 
       startActivity(i); 
       break; 
      case R.id.exit: 
       finish(); 
       break; 
      } 

     }; 

    } 

我知道錯誤有事情做與無效,但它之前

回答

0

移動的onClick ussually摸索出的startApp的:)

private void startApp(){ 

    View Patient_Button = findViewById(R.id.patientButton); 
    Patient_Button.setOnClickListener(this); 
    View Doctor_Button = findViewById(R.id.doctorButton); 
    Doctor_Button.setOnClickListener(this); 
    View About_Option = findViewById(R.id.aboutButton); 
    About_Option.setOnClickListener(this); 
    View Exit_Option = findViewById(R.id.exit); 
    Exit_Option.setOnClickListener(this); 
} 

public void onClick(View v) { 
     switch (v.getId()) { 
     case R.id.patientButton: 
      Intent b = new Intent(this, Detailed_ModeActivity.class); 
      startActivity(b); 
      break; 
     case R.id.doctorButton: 
      Intent a = new Intent(this, Detailed_ModeActivity.class); 
      startActivity(a); 
      break; 
     case R.id.aboutButton: 
      Intent i = new Intent(this, About.class); 
      startActivity(i); 
      break; 
     case R.id.exit: 
      finish(); 
      break; 
     } 

} 
+0

我在哪裏可以將它移動到?? – YoKaGe

+0

更新回答 – logcat

+0

謝謝,但我有另一個問題?該項目將編譯,但它強制關閉,當我嘗試在我的手機上運行:它說,應用程序已意外停止 – YoKaGe