Search code examples
javaandroidandroid-wifi

Wifi connection issues


I'm currently receiving the following errors in wifi communication:

Cannot refer to a non-final variable wifi inside an inner class defined in a different method

List<ScanResult> results = wifi.getScanResults();

Cannot be resolved to a variable

connectivity.setRadio(NetworkType.WIFI, false);
connectivity.setRadio(NetworkType.WIFI, true);
connectivity.setNetworkPreference(NetworkPreference.PREFER_WIFI);
int networkType = networkInfo.getType();
wifi.enableNetwork(netID, disableAllOtherstrue);

Thanks For any help in understanding these!!


Solution

  • Make your wifi variable final. The exception message is self explanatory. This is because you are probably using an inner class or an anonymous constructor for a Listener.

    EDIT

    The comment provided by imran khan will also do the trick. It depends what you think is best for your case.