使用Library CWAC CAM2拍摄时,方向更改时崩溃

时间:2016-02-29 18:18:13

标签: android commonsware-cwac greenrobot-eventbus

我使用CommonsWare库cwac:cam2

在我的nexus 5 Android 6(锤击/锤击)上崩溃了

当我更改录制/照片捕捉活动的方向时。该错误在我的设备上是系统的。

stacktrace:

E / AndroidRuntime: FATAL EXCEPTION: main
Process: com.m360learning.android, PID: 9637
java.lang.RuntimeException: Unable to start activity ComponentInfo {
 com.m360learning.android / com.commonsware.cwac.cam2.VideoRecorderActivity
}: de.greenrobot.event.EventBusException: Subscriber class com.commonsware.cwac.cam2.CameraFragment already registered to event class com.commonsware.cwac.cam2.CameraController$ControllerReadyEvent
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java: 2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java: 2476)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java: 4077)
at android.app.ActivityThread. - wrap15(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java: 1350)
at android.os.Handler.dispatchMessage(Handler.java: 102)
at android.os.Looper.loop(Looper.java: 148)
at android.app.ActivityThread.main(ActivityThread.java: 5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java: 726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java: 616)
Caused by: de.greenrobot.event.EventBusException: Subscriber class com.commonsware.cwac.cam2.CameraFragment already registered to event class com.commonsware.cwac.cam2.CameraController$ControllerReadyEvent
at de.greenrobot.event.EventBus.subscribe(EventBus.java: 179)
at de.greenrobot.event.EventBus.register(EventBus.java: 165)
at de.greenrobot.event.EventBus.register(EventBus.java: 133)
at com.commonsware.cwac.cam2.CameraFragment.onStart(CameraFragment.java: 123)
at android.app.Fragment.performStart(Fragment.java: 2244)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java: 1002)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java: 1148)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java: 1130)
at android.app.FragmentManagerImpl.dispatchStart(FragmentManager.java: 1958)
at android.app.FragmentController.dispatchStart(FragmentController.java: 163)
at android.app.Activity.performStart(Activity.java: 6274)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java: 2379)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java: 2476) 
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java: 4077) 
at android.app.ActivityThread. - wrap15(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java: 1350) 
at android.os.Handler.dispatchMessage(Handler.java: 102) 
at android.os.Looper.loop(Looper.java: 148) 
at android.app.ActivityThread.main(ActivityThread.java: 5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java: 726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java: 616) 

非常感谢您的支持,修复工作非常谨慎。

1 个答案:

答案 0 :(得分:2)

问题是您正在尝试注册服务两次输入代码,如您在跟踪中看到的那样。该服务未注册,因此最简单的选择是在注册服务之前检查服务是否已注册EventBus.getDefault()。isRegistered(...)或者检查onStart是否为事件服务isn&t; t停了,因此仍然登记。例如:

if (!EventBus.getDefault().isRegistered(this)) {
    EventBus.getDefault().register(this);
}