gpt4 book ai didi

java - 安卓相机: Unboxing of 'characteristics.get(CameraCharacteristics.LENS_FACING)' may produce NPE

转载 作者:行者123 更新时间:2023-12-01 10:41:18 25 4
gpt4 key购买 nike

我正在实现Camera2,当我设置相机输出时,我收到以下警告(我无法重现可能发生的任何“npe”)(我从 google 的示例中获取代码)以下行给出以下警告:

"Unboxing of 'characteristics.get(CameraCharacteristics.LENS_FACING)' may produce NPE."

 for (String cameraId : manager.getCameraIdList()) {
CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId);

if (characteristics.get(CameraCharacteristics.LENS_FACING)
== CameraCharacteristics.LENS_FACING_FRONT) { //THESE LINE IS WHERE THE WARNING APPEARS
continue;
}
....

是否有人知道如何以正确的方式检查此情况,以便在发生这种情况时捕获此情况?

最佳答案

您将其与原始int进行比较,并且characteristics.get(CameraCharacteristics.LENS_FACING)可能返回一个Integer,它是目的。发生的事情是你将拥有

Integer integer = characteristics.get(CameraCharacteristics.LENS_FACING);
if (integer.intValue() == CameraCharacteristics.LENS_FACING_FRONT) {

}

如果integer为空,您将获得一个NPE访问intValue()

关于java - 安卓相机: Unboxing of 'characteristics.get(CameraCharacteristics.LENS_FACING)' may produce NPE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34402419/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com