0

What is this error and how do I fix this? This is driving me nuts.

public static void NSOMUHDialog(final Context context) {
  AlertDialog.Builder builder = new AlertDialog.Builder(context);
  builder.setTitle("Menu");
  builder.setCancelable(true);
  builder.setItems(new CharSequence[]{"Announcements", "Rate us", "Get support", "How to use?", "Share download link"},
      new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
              switch (which) {
                case 0:
                  if (NSOMUHUpdateChecker.getInstance(context).isOnline()) {
                     // internet is available, fetch announcements
                     new NSOMUHFetchAnnouncements().execute();
                  } else {
                     // device is offline
                     Toast.makeText(context, "not connected", Toast.LENGTH_LONG).show();
                  }
                  break;

ERROR:

NSOMUHMenu.this' cannot be referenced from a static context

ישו אוהב אותך
  • 28,609
  • 11
  • 78
  • 96
user8091716
  • 45
  • 1
  • 6

2 Answers2

0

You can not call something that does not exist. Since you have not created an object, the non-static method does not exist yet. A static method (by definition) always exists.

Please use static keyword in your NSOMUHUpdateChecker class

 public static void getInstance(Context context) 
vishal jangid
  • 2,967
  • 16
  • 22
0

just remove the static keyword from the function declaration

Naseem Ahmad
  • 103
  • 9