2015-10-16 79 views
0

工作当我尝试在模拟器上我说不幸GeoQuiz已经停止bignerdranch

“不幸的是,GeoQuiz已停止工作”选项卡信息运行我的应用程序.......

GeoQuiz是我的应用程序的名字....... 这里是在QuizActivity.java我的活动类文件

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(果冻豆) 和目标的版本是API 21:Android的5.0(棒棒堂)

+0

欢迎堆栈溢出。我已经修复了您的帖子中的一些英文问题。我很高兴用'>'标出了你的错误信息。 –

+0

谢谢先生:) –

回答

2

你不要在正确的地方拨打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 
+1

谢谢!! 它现在的作品:) 你真的帮了我 ......这个网站是如此酷 –