Note that there are some explanatory texts on larger screens.

plurals
  1. PONullPointerException When calling Dialog Fragment
    primarykey
    data
    text
    <p>i want to create Dialog using fragment following this [link][1],</p> <p>Here my code for dialog fragment</p> <pre><code>public class AlertFragmentDialog extends DialogFragment { public static final int DIALOG_EXIT_ALERT = 1; private static final String KEY_TITLE = "titles"; private static final String KEY_DIALOG = "dialogtype"; public static DialogFragment newInstance(int _title,int _dialogType){ AlertFragmentDialog frag = new AlertFragmentDialog(); Bundle args = new Bundle(); args.putInt(KEY_TITLE, _title); args.putInt(KEY_DIALOG, _dialogType); frag.setArguments(args); return null; } @Override public Dialog onCreateDialog(Bundle savedInstanceState) { switch(getArguments().getInt(KEY_DIALOG)) { case DIALOG_EXIT_ALERT : return new AlertDialog.Builder(getActivity()).setTitle(getArguments().getInt(KEY_TITLE)) .setPositiveButton(R.string.global_yes,new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { ((MainActivity)getActivity()).doYesConfirmationClick(); } }) .setNegativeButton(R.string.global_no, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { ((MainActivity)getActivity()).doNoConfirmationClick(); } }).create(); } return null; } } </code></pre> <p>And call it using this code </p> <pre><code>FragmentManager fm = getSupportFragmentManager(); DialogFragment alertDialog = AlertFragmentDialog.newInstance(R.string.global_exit_alert,AlertFragmentDialog.DIALOG_EXIT_ALERT); alertDialog.show(fm, "dialog"); </code></pre> <p>But when i run i got error NullPointerException on my emulator. Error at alertDialog.show(fm, "dialog"); Please help i'm not sure what's wrong with my code..</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload