2016-04-25 11 views
2

私はPHP mysql json parsorを使用してクイズアプリを作成していますが、そのプログラムではxmlファイルの作成時にエラー "Caused by: android.view.InflateException: Binary XML file line #44: Error inflating class RadioButton"が表示されます。 私はQuizActivity.javaクラッシュログでこれらのコードを使用しています作成したコンテンツにエラーがスローされますクラスRadioButtonをエミュレートする際にエラーが発生しました

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 List<QuizWrapper> parsedObject; 
@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:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context=".QuizActivity"> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/question" 
    android:id="@+id/quiz_question" 
    android:layout_alignParentTop="true" 
    android:layout_marginLeft="10dp" 
    android:layout_marginRight="10dp" 
    android:layout_marginEnd="10dp" 
    android:layout_marginStart="10dp" 
    android:layout_marginTop="20dp" 
    android:textSize="20sp" 
    android:textColor="#000000" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" /> 

<RadioGroup 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/quiz_question" 
    android:layout_alignLeft="@+id/quiz_question" 
    android:layout_alignStart="@+id/quiz_question" 
    android:layout_marginTop="40dp" 
    android:id="@+id/radioGroup"> 

    <RadioButton 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:id="@+id/radio0" 
     android:textSize="15sp" 
     android:textColor="#000000" 
     android:text="@string/app_name" 
     android:layout_marginBottom="10dp" 
     android:paddingLeft="20dp" 
     android:button="@drawable/radio_bg" 
     android:checked="false" /> 

    <RadioButton 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:id="@+id/radio1" 
     android:textSize="15sp" 
     android:textColor="@color/black" 
     android:text="@string/app_name" 
     android:layout_marginBottom="10dp" 
     android:paddingLeft="20dp" 
     android:button="@drawable/radio_bg" 
     android:checked="false" /> 

    <RadioButton 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:id="@+id/radio2" 
     android:textSize="15sp" 
     android:textColor="@color/black" 
     android:text="@string/app_name" 
     android:layout_marginBottom="10dp" 
     android:paddingLeft="20dp" 
     android:button="@drawable/radio_bg" 
     android:checked="false" /> 

    <RadioButton 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:id="@+id/radio3" 
     android:textSize="15sp" 
     android:textColor="@color/black" 
     android:text="@string/app_name" 
     android:paddingLeft="20dp" 
     android:button="@drawable/radio_bg" 
     android:checked="false" /> 

    </RadioGroup> 

<Button 
    android:layout_height="wrap_content" 
    android:layout_width="160dp" 
    android:gravity="center" 
    android:id="@+id/nextquiz" 
    android:textColor="@color/white" 
    android:text="@string/next_questions" 
    android:background="@drawable/quizbutton" 
    android:layout_marginRight="10dp" 
    android:padding="5dp" 
    android:layout_alignParentRight="true" 
    android:layout_alignBaseline="@+id/previousquiz"/> 

<Button 
    android:layout_height="wrap_content" 
    android:layout_width="160dp" 
    android:gravity="center" 
    android:id="@+id/previousquiz" 
    android:textColor="@color/white" 
    android:text="@string/previous_questions" 
    android:background="@drawable/quizbutton" 
    android:layout_below="@+id/radioGroup" 
    android:layout_alignLeft="@+id/radioGroup" 
    android:padding="5dp" 
    android:layout_marginTop="20dp" 
    android:layout_alignStart="@+id/radioGroup" /> 

Caused by: android.view.InflateException: Binary XML file line #45: Error inflating class RadioButton 
+0

クラッシュログを追加してください – USKMobility

+0

新しい 'id'を付けたい場合を除いて' @ + id'を使用しないでください。 viewへの他のすべての参照については、 '@ id'だけを実行します。しかし、私はこのエラーを引き起こすとは思いません.... – Opiatefuchs

+0

あなたが以前の変更を加えた場合、あなたのプロジェクトをきれいにしてください.... – Opiatefuchs

答えて

0

私はあなたが方向性を見逃していると思います<RadioGroup>要素の属性です。あなたの< RadioGroup>要素内

android:orientation = "vertical" 

、試してみて、その後、きれいにし、プロジェクトを再構築してみてください。

+1

私はこの "android:orientation =" vertical ""を使用しようとしましたが、何も変わりません。 –

+0

私はあなたのコードを実行しており、それは完全に動作しています。ボタン属性で指定したセレクタに問題がある可能性があります。セレクタが正しいことを確認してください。それ以外の場合は、コードに問題はありません。 –

関連する問題