DialogFragment argument and nullpointer exception

删除回忆录丶 提交于 2019-12-01 06:10:42

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");
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!