-1

Problem I'm having:

  • 4th line down I get an error saying "com.example.wifilocator.MainActivity" is not an enclosing class

Code in question(From MainActivity) - 4th line:

class wifi {
    int signalStrength = 0;
    int loopToggle = 0;
    Context context = MainActivity.this;

    @RequiresApi(api = Build.VERSION_CODES.ICE_CREAM_SANDWICH)
    public void loop() throws InterruptedException {
        while (loopToggle == 0) {
            WifiManager signalStrength = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
            String wifiInfo = WifiManager.EXTRA_WIFI_INFO;
            TextView textView = (TextView) textView.findViewById(R.id.readOut);
            Thread.sleep(1000);
        }
    }
}

Thanks so much for any help! :)

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129

2 Answers2

0

This line Context context = MainActivity.this; make no sence unless it's inside MainActivity, try something like this instead :

@RequiresApi(api = Build.VERSION_CODES.ICE_CREAM_SANDWICH)
    public void loop(Context context) throws InterruptedException {
        while (loopToggle == 0) {
            WifiManager signalStrength = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
            String wifiInfo = WifiManager.EXTRA_WIFI_INFO;
            TextView textView = (TextView) textView.findViewById(R.id.readOut); //this line makes no sence too
            Thread.sleep(1000);
        }
    }

And call it from your MainActivity like this :

loop(MainActivity.this);

Hope this helps

Benkerroum Mohamed
  • 1,867
  • 3
  • 13
  • 19
0

The error is because you're placing the wifi outside the MainActivity class like this:

public class MainActivity extends AppCompatActivity {
  ...
}

class wifi {
  ...
}

wifi class must be inside the MainActivity class, like this:

public class MainActivity extends AppCompatActivity {
  ...

  class wifi {
     ...
  }
}
ישו אוהב אותך
  • 28,609
  • 11
  • 78
  • 96