2013-03-24 113 views
1

一個非常奇怪的錯誤...我在onResume()和onPause()方法中註冊和取消註冊一個接收者。這是在的onStop()方法的代碼:IllegalArgumentException未捕獲

try{ 
     this.unregisterReceiver(this.sdCardReceiver); 
    }catch(IllegalArgumentException e){ 
     Log.d(MyOwnLife.LOG_LIFEGALLERY, "ActivityVideo - onStop unregisterReceiver:"+e); 
    } 

而且我得到以下錯誤:

Caused by: java.lang.IllegalArgumentException: Receiver not registered: [email protected]43f8 

我趕上了錯誤......但我的應用程序崩潰反正...任何想法?

以下是完整的日誌:

java.lang.RuntimeException: Unable to stop activity {myownlife.pigeau/myownlife.pigeau.activityVideo.ActivityVideo}: java.lang.IllegalArgumentException: Receiver not registered: [email protected]43f8 
at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:2434) 
at android.app.ActivityThread.handleWindowVisibility(ActivityThread.java:2506) 
at android.app.ActivityThread.access$1900(ActivityThread.java:117) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:958) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:130) 
at android.app.ActivityThread.main(ActivityThread.java:3687) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:507) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625) 
at dalvik.system.NativeStart.main(Native Method) 
Caused by: java.lang.IllegalArgumentException: Receiver not registered: [email protected]43f8 
at android.app.LoadedApk.forgetReceiverDispatcher(LoadedApk.java:610) 
at android.app.ContextImpl.unregisterReceiver(ContextImpl.java:851) 
at android.content.ContextWrapper.unregisterReceiver(ContextWrapper.java:342) 
at myownlife.pigeau.activityVideo.ActivityVideo.onStop(ActivityVideo.java:224) 
at android.app.Instrumentation.callActivityOnStop(Instrumentation.java:1170) 
at android.app.Activity.performStop(Activity.java:3884) 
at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:2431) 
... 11 more 
+0

能否請你加logcat的輸出以及 – Ali 2013-03-24 11:20:50

+0

爲什麼你不使用你喜歡的調試器找出發生了什麼? – 2013-03-24 11:21:39

+0

似乎你正在嘗試做一些自定義的事情: [1]:http://stackoverflow.com/questions/8050730/viewflipper-receiver-not-registered – Ali 2013-03-24 11:26:20

回答

1

如果您使用的是本地廣播那就試試這個

onPause(){ 
    LocalBroadcastManager.getInstance(this).unregisterReceiver(broadcastReceiver); 
    } 
+0

我希望我可以給Avinash百萬upvotes!這個問題讓我瘋狂了幾個小時,而這個簡單的技巧完全解決了這個問題! – 2015-05-14 20:51:33