gpt4 book ai didi

android - java.lang.RuntimeException : Fail to get camera info 错误

转载 作者:可可西里 更新时间:2023-11-01 18:48:07 27 4
gpt4 key购买 nike

在我的 PhotoCaptureActivity.java 的 onCreate() 中我有:

OrientationEventListener oeL = new  OrientationEventListener(this) {        
public void onOrientationChanged(int orientation) {
if (orientation == ORIENTATION_UNKNOWN) return;
try {
android.hardware.Camera.CameraInfo info =
new android.hardware.Camera.CameraInfo();
android.hardware.Camera.getCameraInfo(currentCameraId, info);
orientation = (orientation + 45) / 90 * 90;
int rotation = 0;
if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {
rotation = (info.orientation - orientation + 360) % 360;
} else { // back-facing camera
rotation = (info.orientation + orientation) % 360;
}
if(camera != null) {
Camera.Parameters parameters = camera.getParameters();
parameters.setRotation(rotation);
savingRotation = rotation;
}
} catch(Exception e) {
return;
}
}
};
oeL.enable();

此行发生异常:android.hardware.Camera.getCameraInfo(currentCameraId, info);

java.lang.RuntimeException: Fail to get camera info
at android.hardware.Camera.getCameraInfo(Camera.java)
at cic.signin.macio.jun.activities.PhotoCaptureActivity$3.onOrientationChanged(PhotoCaptureActivity.java:70)
at android.view.OrientationEventListener$SensorEventListenerImpl.onSensorChanged(OrientationEventListener.java:143)
at android.hardware.SensorManager$ListenerDelegate$1.handleMessage(SensorManager.java:584)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(NativeStart.java)

我的问题是:OrientationEventListener的onOrientationChanged()中的android.hardware.Camera.getCameraInf(currentCameraId, info)调用过于频繁导致异常?如何解决这个问题?顺便说一句,这个异常没有发生在 4.0 和 4.1 上,只发生在某些设备上。

最佳答案

大胆猜测 -它与您的代码无关,请重置设备并重试。有时我的相机(甚至闪光灯停止工作)并且唯一修复它的方法是重置设备。

关于android - java.lang.RuntimeException : Fail to get camera info 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22383708/

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