2016-07-08 72 views
-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

任何幫助表示讚賞

+1

你有'進口android.content.BroadcastReceiver;'在你的'ReInstallReceiver'類的頂部'import's? –

+0

是的,我有它 –

+0

嗯,你可能會嘗試清理/重建,特別是如果你最近改變了這個類。另外,你的'if'條件不對。使用'String#equals()'方法而不是'=='。 (當然,這不是問題,但顯然是。) –

回答

1

這條線清單:

<receiver android:name=".handleupgrade.ReInstallReceiver"> 

意味着你的接收器裏面handleupgrade包。但你的接收器是com.packagename.ReInstallReceiver

變化艙單行:

<receiver android:name="com.packagename.ReInstallReceiver"> 
+0

您是否嘗試重建該項目? –

相關問題