gpt4 book ai didi

android - 相机不工作 - startPreview 失败

转载 作者:行者123 更新时间:2023-11-29 14:28:16 27 4
gpt4 key购买 nike

我的相机应用程序在 Android 2.x 设备上运行时总是出现异常。在较新的 Android 设备上,该应用程序运行良好。

堆栈跟踪:

10-31 19:51:52.187: W/System.err(14904): java.lang.RuntimeException: startPreview failed
10-31 19:51:52.195: W/System.err(14904): at android.hardware.Camera.startPreview(Native Method)
10-31 19:51:52.195: W/System.err(14904): at com.example.MainActivity.startCamera(MainActivity.java:418)
10-31 19:51:52.195: W/System.err(14904): at com.example.MainActivity.surfaceChanged(MainActivity.java:467)
10-31 19:51:52.195: W/System.err(14904): at android.view.SurfaceView.updateWindow(SurfaceView.java:558)
10-31 19:51:52.195: W/System.err(14904): at android.view.SurfaceView.dispatchDraw(SurfaceView.java:350)
10-31 19:51:52.195: W/System.err(14904): at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
10-31 19:51:52.195: W/System.err(14904): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
10-31 19:51:52.195: W/System.err(14904): at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
10-31 19:51:52.195: W/System.err(14904): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
10-31 19:51:52.195: W/System.err(14904): at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
10-31 19:51:52.195: W/System.err(14904): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
10-31 19:51:52.195: W/System.err(14904): at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
10-31 19:51:52.195: W/System.err(14904): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
10-31 19:51:52.195: W/System.err(14904): at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
10-31 19:51:52.203: W/System.err(14904): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
10-31 19:51:52.203: W/System.err(14904): at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
10-31 19:51:52.203: W/System.err(14904): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
10-31 19:51:52.203: W/System.err(14904): at android.view.View.draw(View.java:6883)
10-31 19:51:52.203: W/System.err(14904): at android.widget.FrameLayout.draw(FrameLayout.java:357)
10-31 19:51:52.203: W/System.err(14904): at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1964)
10-31 19:51:52.203: W/System.err(14904): at android.view.ViewRoot.draw(ViewRoot.java:1529)
10-31 19:51:52.203: W/System.err(14904): at android.view.ViewRoot.performTraversals(ViewRoot.java:1266)
10-31 19:51:52.203: W/System.err(14904): at android.view.ViewRoot.handleMessage(ViewRoot.java:1867)
10-31 19:51:52.203: W/System.err(14904): at android.os.Handler.dispatchMessage(Handler.java:99)
10-31 19:51:52.203: W/System.err(14904): at android.os.Looper.loop(Looper.java:130)
10-31 19:51:52.203: W/System.err(14904): at android.app.ActivityThread.main(ActivityThread.java:3687)
10-31 19:51:52.203: W/System.err(14904): at java.lang.reflect.Method.invokeNative(Native Method)
10-31 19:51:52.203: W/System.err(14904): at java.lang.reflect.Method.invoke(Method.java:507)
10-31 19:51:52.203: W/System.err(14904): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
10-31 19:51:52.203: W/System.err(14904): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
10-31 19:51:52.203: W/System.err(14904): at dalvik.system.NativeStart.main(Native Method)

最佳答案

在 SurfaceView Holder 上,确保将类型设置为 SURFACE_TYPE_PUSH_BUFFERS

@Override
public void onCreate(Bundle savedInstanceState) {
// ...
SurfaceView s=(SurfaceView)findViewById(R.id.surface);
SurfaceHolder h=s.getHolder();
h.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}

关于android - 相机不工作 - startPreview 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13163924/

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