【发布时间】:2014-07-14 11:32:41
【问题描述】:
我知道我的问题可能很愚蠢,但我是 Android 应用程序开发和 Eclipse 方面的新手,但遇到了无法在互联网上找到解决方案的问题。 我正在制作多活动应用程序,当我在其中一个活动中有两个按钮并希望它们中的每一个都导致不同的其他活动时,应用程序就会崩溃。当我带领他们一起参加一项活动时,一切都很好。这是我的代码,希望我的问题不要像我想的那样愚蠢。
public class Home extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
Button myButton = (Button) findViewById(R.id.tables);
myButton.setOnClickListener(goToTables);
Button mySecondButton = (Button) findViewById(R.id.reservations);
mySecondButton.setOnClickListener(goToMenu);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.home, menu);
return true;
}
private OnClickListener goToTables = new OnClickListener(){
@Override
public void onClick(View v) {
doButton();
}};
private void doButton()
{
startActivity(new Intent(this, Tables.class));
}
private OnClickListener goToMenu = new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
doSecondButton();
}};
private void doSecondButton()
{
startActivity(new Intent(this, Menu.class));
}
}
goToTables 完美运行,但我错过了 goToMenu 中需要更改的重要内容。我的其他活动是:表格和菜单。有人可以告诉我我哪里错了吗?提前致谢!
【问题讨论】:
-
由于在代码开发过程中总是会发生崩溃,现在最好的利用时间是了解 logcat 并发布堆栈跟踪。堆栈跟踪将使崩溃非常容易诊断。
标签: java android button hyperlink