My class should pass an argument to DialogFragment, but my app crashes inside onCreate method (of dialog class) for a NullPointerException. Dialog fragment class portion of
You're creating a ConfirmDialog
via the constructor, then calling newInstance()
, which creates another (proper) ConfirmDialog
. However you then discard that proper instance.
To fix this:
Your newInstance()
method should be static:
public static ConfirmDialog newInstance(String f) {
ConfirmDialog d = new ConfirmDialog();
Bundle args = new Bundle();
args.putString("FILE_NAME", f);
d.setArguments(args);
return d;
}
And showConfirmDialog()
should be changed so it uses the newInstance()
method properly.
private void showConfirmDialog(String file) {
FragmentManager fm = getSupportFragmentManager();
Log.i("SHOWFILEACTIVITY", file);
ConfirmDialog dialog = ConfirmDialog.newInstance(file);
dialog.show(fm, "fragment_confirm_dialog");
}