2011-06-27 20 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(); 
} 

} 

なぜコードが停止したのですか? それは前に働いていましたが、私はここで何も変更しませんでした。 コメントをしようとしました Intent gameIntent = new Intent(this、Game.class); startActivity(gameIntent); これが動作するかどうかを確認してください。主な活動の強制終了

Javaのランダムエラーにうんざりです。 これはコーヒーを飲んだ後に機能します。

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

ものであり、ボタン場合は、次のようにボタンとしてそれらをキャスト:また

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

+0

LogCatエラー出力を投稿できますか? –

+0

LogCatを使用している場合は、取得している例外を投稿してください。 – whirlwin

+1

コードがランダムに破られることはありません(重要な作業を行う乱数がない限り)。スタックトレースとは何ですか? – Haphazard

答えて

1

あなたの主なレイアウトを見なければ、私はこれだけを引き起こしている可能性が夫婦の問題を見ることができます、

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

あなたのAboutクラスは、これがタイプミスdはあなたのヌルエラーの犯人かもしれません。

+0

絶対に誤字はありません。私はチェックして、私は私の心にこのエラーを含め、チェックした前に、意図とこのタイプミスの問題があった。 – Cr3a70r

+0

私はここで何も変わっていないが、それは動作しません。私は作業コピー(compilled)のバックアップを持って、それは同じ問題があります。しかし、それがうまくいった前に... – Cr3a70r

+1

よくタイプミスか、大文字でクラス名を始めるべきではありません。ボタンをボタンとしてキャストする必要があります。 –

関連する問題