虽然我知道已经有一些答案,但我不太了解它们,因为我只是
Android编程的初学者.我尝试使用以下代码实例化我的接收器:
android:name="com.example.android.exampleapp.MainActivity$NetworkChangeReceiver"
android:enabled="true"
android:label="NetworkChangeReceiver">
但它不起作用. logcat说:
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
我在MainActivity.java中的部分代码如下所示:
public class NetworkChangeReceiver extends BroadcastReceiver {
/* All my code that reacts when WiFi state changes are here */
}
我知道这个问题听起来很容易,但我真的不知道如何解决这个错误.我读过this(我觉得有点无效 – 我没有空的构造函数)和一堆其他的在线教程,但我仍然无法得到它.任何帮助,将不胜感激 :)