Unable to instantiate receiver: class has no null argument

Although I know that there are some answers there already, I do not quite understand them, since I am only a beginner in programming on Android. 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 didn’t work. Latitude 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 may seem easy, but I seriously don’t know how to resolve this error. I read this one (which I think is invalid - I don't have an empty constructor) and many other online lessons, but I still can't get it. Any help would be appreciated :)

+4
1

:

public class NetworkChangeReceiver extends BroadcastReceiver

public static class NetworkChangeReceiver extends BroadcastReceiver

, NetworkChangeReceiver public Java.

+7

Source: https://habr.com/ru/post/1627303/


All Articles