gpt4 book ai didi

java - 不幸的是,GeoQuiz 已停止在 bignerdranch 工作

转载 作者:行者123 更新时间:2023-12-02 04:17:24 25 4
gpt4 key购买 nike

当我尝试在模拟器上运行我的应用程序时,我收到一条选项卡消息

"unfortunately,GeoQuiz has stopped working" .......

GeoQuiz 是我的应用程序的名称......这是 QuizActivity.java 文件中的我的 Activity 类

public class QuizActivity extends ActionBarActivity {

private Button mTrueButton;

private Button mFalseButton;


@Override
protected void onCreate(Bundle savedInstanceState) {

mTrueButton=(Button) findViewById(R.id.true_button);
mTrueButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(QuizActivity.this,R.string.correct_toast,Toast.LENGTH_SHORT).show();
}
});

mFalseButton=(Button) findViewById(R.id.false_button);
mFalseButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(QuizActivity.this, R.string.incorrect_toast, Toast.LENGTH_SHORT).show();
}
});
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_quiz);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_quiz, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();

//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}

}

我的应用程序中根本没有图像这个应用程序的最小 sdk 版本是 API 16:android 4.1 (jelly bean)目标版本为API 21:android 5.0 (Lollipop)

最佳答案

您没有在正确的位置调用setContentView:您可以在 onCreate 方法的末尾调用它!您必须将这两行移至 onCreate 方法的开头:

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_quiz);

因此,您会在此处收到 NullPointerException:

 mTrueButton=(Button) findViewById(R.id.true_button);
mTrueButton.setOnClickListener(new View.OnClickListener() { // NPE

关于java - 不幸的是,GeoQuiz 已停止在 bignerdranch 工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33168672/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com