lundi 1 août 2016

NullPointerException AlertDialog.Builder

Hi everyone :)

I've been looking into this for a couple of hours and changed the code quite a few times however the nullpointerexception error is still appearing

The problem is occuring when my "WorkOn" class calls another class called "Dialogs"

So this is my WorkOn Class

Code (Java):

  1.     Dialogs saveDialog = new Dialogs(context);

  2. //constructor

  3.     public WorkOn(Context context) {
  4.     this.context = context;

  5. }

  6.     public void OnTime(View v) {
  7.             saveDialog.WorkOnSavedDialog(v);

  8.         }

  9.     });

  10. }

This is my Dialogs class

Code (Java):

  1. public class Dialogs extends AppCompatActivity  {

  2. //constructor

  3.     this.context = context;

  4. }

  5. public void WorkOnSavedDialog(View v) {
  6.     AlertDialog.Builder alert = new AlertDialog.Builder(Dialogs.this);

  7.     alert.setTitle("Work On File Saved");

  8.     alert.setMessage("[Displaying for Test] Work On File Saved");

  9.     alert.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {

  10.                 public void onClick(DialogInterface dialog, int which) {

  11.                     // continue with delete

  12.                 }

  13.             });

  14.     alert.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {

  15.                 public void onClick(DialogInterface dialog, int which) {

  16.                     // do nothing

  17.                 }

  18.             });

  19.     alert.setIcon(android.R.drawable.ic_dialog_alert);

  20.     alert.show();

  21. }

  22. }

The nullpointer excpection is happening because of

Code (Java):

  1. AlertDialog.Builder alert = new AlertDialog.Builder(Dialogs.this);

do you have any idea why this is happening?

Let's block ads! (Why?)



NullPointerException AlertDialog.Builder

Aucun commentaire:

Enregistrer un commentaire