Tôi có lớp bên trong như máy thu phát sóng:BroadcastReceiver: không thể khởi tạo lớp; không có constructor rỗng
public class ManualBacklightReceiver extends BroadcastReceiver {
public static final String ACTION_MANUAL_BACKLIGHT = "com.android.systemui.statusbar.powerwidget.MANUAL_BACKLIGHT";
public ManualBacklightReceiver() {
}
@Override
public void onReceive(Context context, Intent intent) {
Log.d("ManualBacklightReceiver", intent.getAction());
}
};
AndroidManifest:
<receiver android:name=".statusbar.powerwidget.PowerWidgetGrid$ManualBacklightReceiver">
<intent-filter>
<action android:name="com.android.systemui.statusbar.powerwidget.MANUAL_BACKLIGHT"/>
</intent-filter>
</receiver>
Và khi tôi gửi ý với mã này: ý Ý định = Ý định mới();
intent.setAction("com.android.systemui.statusbar.powerwidget.MANUAL_BACKLIGHT");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.sendBroadcast(intent);
tôi nhận được những trường hợp ngoại lệ:
java.lang.RuntimeException: Unable to instantiate receiver com.android.systemui.statusbar.powerwidget.PowerWidgetGrid$ManualBacklightReceiver:
java.lang.InstantiationException: can't instantiate class com.android.systemui.statusbar.powerwidget.PowerWidgetGrid$ManualBacklightReceiver; no empty constructor
Caused by: java.lang.InstantiationException: can't instantiate class com.android.systemui.statusbar.powerwidget.PowerWidgetGrid$ManualBacklightReceiver; no empty constructor
Nhưng tôi có một constructor rỗng! Tại sao nó không hoạt động?
Bạn đã thử gọi super(); bên trong constructor của bạn? – Bobbake4
Lỗi tương tự. – arts777