-1
請在下面找到我的代碼爲我的廣播接收器安卓:ClassCastException異常ReInstallReceiver不能轉換到android.content.BroadcastReceiver
public class ReInstallReceiver extends BroadcastReceiver {
private String TAG = "ReInstallReceiver";
@Override
public void onReceive(Context context, Intent intent) {
if(intent != null) {
if(intent.getAction() == Intent.ACTION_MY_PACKAGE_REPLACED) {
//do action
}
}
}
}
Manifest條目:
<receiver android:name=".handleupgrade.ReInstallReceiver">
<intent-filter>
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
</intent-filter>
</receiver>
錯誤:
引起:java.lang.ClassCastException:com.packagename.handleupgrade.ReInstallReceiver無法轉換爲android.content.BroadcastReceiver
任何幫助表示讚賞
你有'進口android.content.BroadcastReceiver;'在你的'ReInstallReceiver'類的頂部'import's? –
是的,我有它 –
嗯,你可能會嘗試清理/重建,特別是如果你最近改變了這個類。另外,你的'if'條件不對。使用'String#equals()'方法而不是'=='。 (當然,這不是問題,但顯然是。) –