Question

I have two radiogroup on FormVisitMapping.java, i put one of them on dialogbox which is trigger by button onClick(). but i get an error nullpointerexception only on my radiogroup where in dialog. even i have a similiar code on both of them. i have no idea why this happenned. i've read a question with similiar issue, but nothing solve my problem. here is my code :

    btninvoice= (Button) findViewById(R.id.btninvoice);
    btninvoice.setOnClickListener(new OnClickListener(){
            @Override
            public void onClick(View arg0) {
              final Dialog dialog3 = new Dialog(FormVisitMapping.this);
              dialog3.setContentView(R.layout.penagihan);
              dialog3.setTitle("Isi Data Penagihan:");
              dialog3.show();
              //other stuff
              RadioGroup tes=(RadioGroup) findViewById(R.id.penagihan);
              switch (tes.getCheckedRadioButtonId()) {
              case R.id.rbtandaterima:
                systemofpayment = "Tanda Terima";
                break;
              case R.id.rbtagihlangsung:
                systemofpayment="Tagih Langsung";
                break;
              default:
                break;
                }
            }
    });

i've got NullPointerException on this line :

switch (tes.getCheckedRadioButtonId()) {

every help will be apriciated.thank you

Was it helpful?

Solution

Your using findViewById() on a wrong view. You haven't included your XML but I'm guessing that you want to find it in dialog's layout.

Change

RadioGroup tes=(RadioGroup) findViewById(R.id.penagihan);

to

RadioGroup tes=(RadioGroup) dialog3.findViewById(R.id.penagihan);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top