You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android CameraX物理设备二次启动Intent崩溃,模拟器正常

CameraX二次启动相机Intent物理设备崩溃问题解决

问题场景

我通过自定义CustomCameraActivity和CustomCamera类实现了CameraX功能,使用pictureActivityResultLauncher启动相机Intent。该功能在Android模拟器上运行完全正常,但在物理设备上,首次拍照操作正常,二次启动相机Intent时会直接崩溃。

错误日志

崩溃时抛出空指针异常:

java.lang.NullPointerException: Attempt to invoke virtual method 'int android.view.Display.getRotation()' on a null object reference

排查过程

  • 尝试手动释放cameraProvider,但问题依然存在
  • 跟踪代码后确认,崩溃根源来自bindCameraUseCases方法中的setTargetRotation调用

解决方法

移除bindCameraUseCases方法里的setTargetRotation相关代码后,二次启动相机Intent的崩溃问题彻底解决。

内容的提问来源于stack exchange,提问作者정민재

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.06 00:42:01