Although I know there are some answers out there already, I don't quite understand them as I am just a beginner in Android programming. I tried to instantiate my receiver using the following code:
<receiver
android:name="com.example.android.exampleapp.MainActivity$NetworkChangeReceiver"
android:enabled="true"
android:label="NetworkChangeReceiver">
<intent-filter>
<action android:name="android.net.wifi.STATE_CHANGE" />
</intent-filter>
</receiver>
but it did not work. The logcat says:
java.lang.RuntimeException:
Unable to instantiate receiver com.example.android.exampleapp.MainActivity$NetworkChangeReceiver:
java.lang.InstantiationException:
class com.example.android.exampleapp.MainActivity$NetworkChangeReceiver has no zero argument constructor
Part of my code in MainActivity.java is shown below:
public class NetworkChangeReceiver extends BroadcastReceiver {
/* All my code that reacts when WiFi state changes are here */
}
I know this question might sound easy, but I seriously do not know how to resolve this error. I had read this (which I think is kinda invalid - I do not have a empty constructor) and a bunch of other online tutorials but I still can't get it. Any help would be appreciated :)