Nullpointerexception When Setting Adapter For Listview In Dialog
I want to display a custom dialog that have a listview inside it. First take a look on my code below. Dialog: protected void onPostExecute(String file_url) {         btnInvite.setO
Solution 1:
Inflate your view and use the object returned by the inflater to look for the ListView inside the layout 
Viewview= inflater.inflate(R.layout.dialog_add, null)
ListViewlv= (ListView) view.findViewById(R.id.lvAddDialog); 
ListviewContactAdapteradapter=newListviewContactAdapter(getActivity(), listContact);
lv.setAdapter(adapter);             
builder.setView(view);
Solution 2:
Change this:
ListviewContactAdapteradapter=newListviewContactAdapter(getActivity(), listContact);
to this:
ListviewContactAdapteradapter=newListviewContactAdapter(YourCLassName.this, listContact);
OR, may be you didn't initialize listContact
Solution 3:
When you get the ListView yet not set te layout in the Dialog. You need build first your dialog and after get the ListView
Check this:
protectedvoidonPostExecute(String file_url) {
    btnInvite.setOnClickListener(newView.OnClickListener() {
        @OverridepublicvoidonClick(View arg0) {
            LayoutInflaterinflater= getActivity().getLayoutInflater();
            AlertDialog.Builderbuilder=newAlertDialog.Builder(getActivity());
            builder.setView(inflater.inflate(R.layout.dialog_add, null))
            .setTitle("Invite people")                  
            .setNegativeButton("Cancel", newOnClickListener() {
                @OverridepublicvoidonClick(DialogInterface dialog, int which) {
                    // TODO Auto-generated method stub
                    dialog.cancel();
                }
            });                                 
            Dialogdialog= builder.create();
            ListViewlv= (ListView) dialog.findViewById(R.id.lvAddDialog); 
            ListviewContactAdapteradapter=newListviewContactAdapter(getActivity(), listContact);
            lv.setAdapter(adapter);     
            dialog.show();                  
            }
    });
 }
}
Post a Comment for "Nullpointerexception When Setting Adapter For Listview In Dialog"