I'm trying to create alertdialogs through a custom dialogframent class
public class Dialogs extends DialogFragment {
@Override
public Dialog onCreateDialog(Bundle saveInstanceState) {
AlertDialog.Builder alert=new AlertDialog.Builder(getActivity());
//additional custom layout here(skipped)
alertDialog=alert.create();
return alert.create();
}
public static Dialogs newInstance(String title, String fields, String buttons) {
Dialogs d = new Dialogs();
Bundle args = new Bundle();
args.putString(TITLE,title);
args.putString(FIELDS, fields);
args.putString(BUTTONS,buttons);
d.setArguments(args);
return d;
}
public List<Button> getButtons() {
return this.buttons;
}
public AlertDialog getDialog(){
return alertDialog;
}
I am calling it in my main activity via
public void AddNewTask() {
Dialogs my_dialog = Dialogs.newInstance("Add New Task",NEW_TASK,NEW_TASK_BUTTON);
my_dialog.getDiag().show();
}
getting
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.AlertDialog.show()' on a null object reference
I have a hunch it's that the arguments were put after the d was created. So the argumnets didn't pass through? Any help is appreciated
Edit: This is not a question of what is a nullpointer exception. I understand very well what it is. I have solve the problem for those that possibly have similar issues in the future. I changed the way the dialog was launched inside main activity. It seems like I was missing a fragmenttransaction.
final Dialogs my_dialog=Dialogs.newInstance("Add New Task", NEW_TASK, NEW_TASK_BUTTON);
FragmentTransaction ft = getFragmentManager().beginTransaction();
my_dialog.show(ft, "dialog");