How to get the selected radio button value from five radio buttons in android? <p>I need to get the selected radio button value out of 5 radio buttons. I have done like :</p> <p><strong>Radio button values from db:</strong></p> <pre><code>op1=(RadioButton)findViewById(R.id.option1); op2=(RadioButton)findViewById(R.id.option2); op3=(RadioButton)findViewById(R.id.option3); op4=(RadioButton)findViewById(R.id.option4); op5=(RadioButton)findViewById(R.id.option5); System.out.println("after lv users "); op1.setText(listItem.getOption1()); op2.setText(listItem.getOption2()); op3.setText(listItem.getOption3()); op4.setText(listItem.getOption4()); op5.setText(listItem.getOption5()); </code></pre> <p><strong>RadioButton check action:</strong></p> <pre><code>radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { public void onCheckedChanged(RadioGroup rg, int checkedId) { for(int i=0; i&lt;radioGroup.getChildCount(); i++) { System.out.print("radiogroup child counts"); System.out.print(radioGroup.getChildCount()); op1 = (RadioButton) radioGroup.getChildAt(i); if(op1.isSelected()== true) { System.out.println("radio i value"); System.out.print("option"+i); //String text = btn.getText(); // do something with text } } } }); </code></pre> <p>But it is not working.It is showing error as <code>NullPointerException</code> at line </p> <pre><code>op1.setText(listItem.getOption1()); </code></pre> <p>Where I went wrong?</p> <p>Help me regarding this.</p>