-1

I am getting java.lang.NullPointerException for this method. I have check the adapter and lists are just fine and the list is ofcourse under fragment_phonelist xml file.

    private void showCustomDialog() {

    final Dialog dialog = new Dialog(SetupProfile.this);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.fragment_phonelist);

    Button done = (Button)dialog.findViewById(R.id.btn_done);
    Button canCel = (Button)dialog.findViewById(R.id.btn_cancel);
    ListView PhoneListView = (ListView)findViewById(R.id.list_phone);

   MyCustomAdapter tst = new MyCustomAdapter(this,ContactName,ContactNumb);
   PhoneListView.setAdapter(tst);

    done.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            dialog.dismiss();

        }
    });
    canCel.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            dialog.dismiss();
        }
    });

    dialog.show();
}

Please any help..

Asad
  • 1,260
  • 13
  • 19
  • Can you add some Log ? or, you can use the debugger to go line by line and see what exactly is Null ... – gioravered May 31 '15 at 11:39
  • 3
    Please post a stacktrace with these types of questions. That said, if your ListView is in the Dialog, then you need to call `dialog.findViewById()` for it, as well. That is, you're missing `dialog` in its initialization line. – Mike M. May 31 '15 at 11:40
  • its working fine when I access the list from activity and add the listView into my activity layout. but I can't find out why its giving null at customdialogBox – Asad May 31 '15 at 11:42
  • 2
    Thanks Mike, I know it was a silly mistake. – Asad May 31 '15 at 11:46

1 Answers1

1

This line

ListView PhoneListView = (ListView)findViewById(R.id.list_phone); 

Shouldn't that be like this:

ListView PhoneListView = (ListView)dialog.findViewById(R.id.list_phone); 
Thomas Vos
  • 12,271
  • 5
  • 33
  • 71