2011-06-27 115 views
0
public class androStrategy extends Activity implements OnClickListener 
{ 
    @Override 
    public void onCreate(Bundle savedInstanceState) 
    { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    // Set up click listeners for all the buttons 
    View game_start = findViewById(R.id.btn_startGame); 
    game_start.setOnClickListener(this); 
    View save_exit = findViewById(R.id.btn_SaveExit); 
    save_exit.setOnClickListener(this); 
    View aboutButton = findViewById(R.id.btn_Help); 
    aboutButton.setOnClickListener(this); 

} 
// ... 

public void onClick(View v) 
{ 
    switch (v.getId()) 
    { 
    case R.id.btn_Help: 
     Intent helpIntent = new Intent(this, about.class); 
     startActivity(helpIntent); 

     break; 
    // More buttons go here (if any) ... 

    case R.id.btn_startGame: 
     Intent gameIntent = new Intent (this, Game.class); 
     startActivity(gameIntent); 
     break; 

    case R.id.btn_SaveExit: 
     finish(); 
     break; 

    } 
} 

@Override 
public void onPause() 
{ 
    super.onPause(); 
} 

@Override 
public void onResume() 
{ 
    super.onResume(); 
} 

} 

爲什麼代碼停止工作? 它工作過,我沒有在這裏改變ANYTHYNG。 我試過評論 意圖gameIntent = new Intent(this,Game.class); startActivity(gameIntent); 看看這是否會工作,而不是。主要活動部隊關閉

那麼我厭倦了Java的隨機錯誤。 現在它工作後,我喝咖啡它does not。

+0

你可以發佈你的LogCat錯誤輸出嗎? –

+0

我希望你使用的是LogCat,如果是的話,發佈你所得到的異常。 – whirlwin

+1

代碼不會隨機破解(除非您有隨機數字執行關鍵任務)。什麼是堆棧跟蹤? – Haphazard

回答

1

沒有看到主佈局,我只能看到可能會導致這幾個問題:

View game_start = findViewById(R.id.btn_startGame); 

如果那些按鈕,投下他們的按鈕是這樣的:

Button game_start = (Button) findViewById(R.id.btn_startGame); 

而且,

Intent helpIntent = new Intent(this, about.class); 

你的關於類應該從首都開始,這使我相信這是一個錯字d可能是你的空錯誤的罪魁禍首。

+0

絕對沒有錯別字。我查了一下,之前我有這個打字錯誤的問題,所以我把這個錯誤包括在我的腦海裏,並檢查。 – Cr3a70r

+0

你看我沒有改變任何東西在這裏,但它沒有工作。我有一個工作副本(compilled)的備份,它也有同樣的問題。但在它工作之前,所以idunno ... – Cr3a70r

+1

好的錯字或不是你應該用大寫字母開始你的類名。你應該把你的按鈕作爲按鈕。 –