2011-06-27 42 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

好的错字或不是你应该用大写字母开始你的类名。你应该把你的按钮作为按钮。 –