开发者

Cannot run Android "Camera Preview" sample

开发者 https://www.devze.com 2023-01-02 14:30 出处:网络
The sample I\'m referring to is: CameraPreview. The program simply force closes upon start up. I\'ve also tried other camera demos that have the same problem.

The sample I'm referring to is: CameraPreview.

The program simply force closes upon start up. I've also tried other camera demos that have the same problem.

I'm trying to run the samples on my Nexus One and the emulator with the same problem on both. I'm not even sure if the emulator should be able to run them or not.

Based on LogCat, the error is:

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.andr开发者_高级运维oid.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)

All I did to try out the sample was create a new Android 2.1update1 Project, named everything according to the supplied Java file, copied the Java file from the URL to the CameraPreview.java file, then run it. Am I supposed to do anything else?

Any help would be appreciated. Thanks in advance.


Add the following to your manifest, as children of the <manifest> element:

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

精彩评论

暂无评论...
验证码 换一张
取 消