Error inflating class RadioButton
Error inflating class RadioButton
我正在使用PHP MySQL JSON解析器创建一个测验应用程序,在运行程序时显示“Caused by: android.view.InflateException: Binary XML file line #44: Error inflating class RadioButton
”这个错误是在创建XML文件时出现的。
我在QuizActivity.java
中使用了以下代码,崩溃日志将在创建内容视图和布局填充器时抛出错误:
public class QuizActivity extends AppCompatActivity { private TextView quizQuestion; private RadioGroup radioGroup; private RadioButton optionOne; private RadioButton optionTwo; private RadioButton optionThree; private RadioButton optionFour; private int currentQuizQuestion; private int quizCount; private QuizWrapper firstQuestion; private ListparsedObject; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_quiz); // setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); quizQuestion = (TextView)findViewById(R.id.quiz_question); radioGroup = (RadioGroup)findViewById(R.id.radioGroup); optionOne = (RadioButton)findViewById(R.id.radio0); optionTwo = (RadioButton)findViewById(R.id.radio1); optionThree = (RadioButton)findViewById(R.id.radio2); optionFour = (RadioButton)findViewById(R.id.radio3); Button previousButton = (Button)findViewById(R.id.previousquiz); Button nextButton = (Button)findViewById(R.id.nextquiz); AsyncJsonObject asyncObject = new AsyncJsonObject(); asyncObject.execute(""); nextButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { int radioSelected = radioGroup.getCheckedRadioButtonId(); int userSelection = getSelectedAnswer(radioSelected); int correctAnswerForQuestion = firstQuestion.getCorrectAnswer(); if(userSelection == correctAnswerForQuestion){ // correct answer Toast.makeText(QuizActivity.this, "You got the answer correct", Toast.LENGTH_LONG).show(); currentQuizQuestion++; if(currentQuizQuestion >= quizCount){ Toast.makeText(QuizActivity.this, "End of the Quiz Questions", Toast.LENGTH_LONG).show(); return; } else{ firstQuestion = parsedObject.get(currentQuizQuestion); quizQuestion.setText(firstQuestion.getQuestion()); String[] possibleAnswers = firstQuestion.getAnswers().split(","); uncheckedRadioButton(); optionOne.setText(possibleAnswers[0]); optionTwo.setText(possibleAnswers[1]); optionThree.setText(possibleAnswers[2]); optionFour.setText(possibleAnswers[3]); } } else{ // failed question Toast.makeText(QuizActivity.this, "You chose the wrong answer", Toast.LENGTH_LONG).show(); return; } } }); previousButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { currentQuizQuestion--; if(currentQuizQuestion < 0){ return; } uncheckedRadioButton(); firstQuestion = parsedObject.get(currentQuizQuestion); quizQuestion.setText(firstQuestion.getQuestion()); String[] possibleAnswers = firstQuestion.getAnswers().split(","); optionOne.setText(possibleAnswers[0]); optionTwo.setText(possibleAnswers[1]); optionThree.setText(possibleAnswers[2]); optionFour.setText(possibleAnswers[3]); } }); }
XML:
Caused by: android.view.InflateException: Binary XML file line #45: Error inflating class RadioButton