无法运行Android“Camera Preview”示例

时间:2010-06-08 20:48:33

标签: android

我所指的样本是:CameraPreview

程序只需在启动时强制关闭。我也尝试过其他有相同问题的相机演示。

我正在尝试在我的Nexus One和模拟器上运行样本,两者都有相同的问题。我甚至不确定模拟器是否应该能够运行它们。

基于LogCat,错误是:

06-08 16:39:10.483: ERROR/AndroidRuntime(6726): Uncaught handler: thread main exiting due to uncaught exception
06-08 16:39:10.494: ERROR/AndroidRuntime(6726): java.lang.RuntimeException: Fail to connect to camera service
06-08 16:39:10.494: ERROR/AndroidRuntime(6726):     at android.hardware.Camera.native_setup(Native Method)
06-08 16:39:10.494: ERROR/AndroidRuntime(6726):     at android.hardware.Camera.<init>(Camera.java:110)
06-08 16:39:10.494: ERROR/AndroidRuntime(6726):     at android.hardware.Camera.open(Camera.java:90)
06-08 16:39:10.494: ERROR/AndroidRuntime(6726):     at com.example.android.apis.graphics.Preview.surfaceCreated(CameraPreview.java:69)
06-08 16:39:10.494: ERROR/AndroidRuntime(6726):     at android.view.SurfaceView.updateWindow(SurfaceView.java:454)
06-08 16:39:10.494: ERROR/AndroidRuntime(6726):     at android.view.SurfaceView.dispatchDraw(SurfaceView.java:287)
06-08 16:39:10.494: ERROR/AndroidRuntime(6726):     at android.view.ViewGroup.drawChild(ViewGroup.java:1529)
06-08 16:39:10.494: ERROR/AndroidRuntime(6726):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
06-08 16:39:10.494: ERROR/AndroidRuntime(6726):     at android.view.View.draw(View.java:6557)
06-08 16:39:10.494: ERROR/AndroidRuntime(6726):     at android.widget.FrameLayout.draw(FrameLayout.java:352)
06-08 16:39:10.494: ERROR/AndroidRuntime(6726):     at android.view.ViewGroup.drawChild(ViewGroup.java:1531)
06-08 16:39:10.494: ERROR/AndroidRuntime(6726):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
06-08 16:39:10.494: ERROR/AndroidRuntime(6726):     at android.view.View.draw(View.java:6557)
06-08 16:39:10.494: ERROR/AndroidRuntime(6726):     at android.widget.FrameLayout.draw(FrameLayout.java:352)
06-08 16:39:10.494: ERROR/AndroidRuntime(6726):     at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1830)
06-08 16:39:10.494: ERROR/AndroidRuntime(6726):     at android.view.ViewRoot.draw(ViewRoot.java:1349)
06-08 16:39:10.494: ERROR/AndroidRuntime(6726):     at android.view.ViewRoot.performTraversals(ViewRoot.java:1114)
06-08 16:39:10.494: ERROR/AndroidRuntime(6726):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1633)
06-08 16:39:10.494: ERROR/AndroidRuntime(6726):     at android.os.Handler.dispatchMessage(Handler.java:99)
06-08 16:39:10.494: ERROR/AndroidRuntime(6726):     at android.os.Looper.loop(Looper.java:123)
06-08 16:39:10.494: ERROR/AndroidRuntime(6726):     at android.app.ActivityThread.main(ActivityThread.java:4363)
06-08 16:39:10.494: ERROR/AndroidRuntime(6726):     at java.lang.reflect.Method.invokeNative(Native Method)
06-08 16:39:10.494: ERROR/AndroidRuntime(6726):     at java.lang.reflect.Method.invoke(Method.java:521)
06-08 16:39:10.494: ERROR/AndroidRuntime(6726):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
06-08 16:39:10.494: ERROR/AndroidRuntime(6726):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
06-08 16:39:10.494: ERROR/AndroidRuntime(6726):     at dalvik.system.NativeStart.main(Native Method)

我尝试的示例是创建一个新的Android 2.1update1项目,根据提供的Java文件命名所有内容,将Java文件从URL复制到CameraPreview.java文件,然后运行它。我该怎么办?

任何帮助将不胜感激。提前谢谢。

1 个答案:

答案 0 :(得分:1)

将以下内容添加到您的清单中,作为<manifest>元素的子项:

<uses-feature android:name="android.hardware.camera" />
<uses-permission android:name="android.permission.CAMERA" />