可以在模拟器上运行系统相机应用程序而不是我自己的相机应用程序

时间:2015-10-03 16:17:29

标签: android android-emulator android-camera

我创建了一个简单的相机应用程序,就像他们在这个例子中所做的那样http://developer.android.com/guide/topics/media/camera.html#custom-camera。但问题是我无法让它在Android模拟器上工作。系统相机应用程序在模拟器上完美运行,但是当我尝试运行它时,我的应用程序崩溃了。模拟器是一个没有皮肤的nexus 5,模拟相机。我尝试了不同的更改设备,但仍然是同样的问题。 这是崩溃后的logcat:

`10-03 15:53:16.750 3146-3146/? E/AndroidRuntime: FATAL EXCEPTION: main
10-03 15:53:16.750 3146-3146/? E/AndroidRuntime: Process: bajsa.myapplication, PID: 3146
10-03 15:53:16.750 3146-3146/? E/AndroidRuntime: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.hardware.Camera.setPreviewDisplay(android.view.SurfaceHolder)' on a null object reference
10-03 15:53:16.750 3146-3146/? E/AndroidRuntime:     at bajsa.myapplication.CameraPreview.surfaceCreated(CameraPreview.java:30)
10-03 15:53:16.750 3146-3146/? E/AndroidRuntime:     at android.view.SurfaceView.updateWindow(SurfaceView.java:582)
10-03 15:53:16.750 3146-3146/? E/AndroidRuntime:     at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:177)
10-03 15:53:16.750 3146-3146/? E/AndroidRuntime:     at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:944)
10-03 15:53:16.750 3146-3146/? E/AndroidRuntime:     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2055)
10-03 15:53:16.750 3146-3146/? E/AndroidRuntime:     at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1107)
10-03 15:53:16.750 3146-3146/? E/AndroidRuntime:     at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6013)
10-03 15:53:16.750 3146-3146/? E/AndroidRuntime:     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
10-03 15:53:16.750 3146-3146/? E/AndroidRuntime:     at android.view.Choreographer.doCallbacks(Choreographer.java:670)
10-03 15:53:16.750 3146-3146/? E/AndroidRuntime:     at android.view.Choreographer.doFrame(Choreographer.java:606)
10-03 15:53:16.750 3146-3146/? E/AndroidRuntime:     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
10-03 15:53:16.750 3146-3146/? E/AndroidRuntime:     at android.os.Handler.handleCallback(Handler.java:739)
10-03 15:53:16.750 3146-3146/? E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:95)
10-03 15:53:16.750 3146-3146/? E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:148)
10-03 15:53:16.750 3146-3146/? E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5417)
10-03 15:53:16.750 3146-3146/? E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Native Method)
10-03 15:53:16.750 3146-3146/? E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
10-03 15:53:16.750 3146-3146/? E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)`

`10-03 15:53:36.270 1796-1808/? E/StrictMode: A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.`

`10-03 15:57:50.330 1027-1027/? I/perfprofd: profile collection skipped (running in emulator)
10-03 16:08:07.460 1349-1365/? E/BluetoothAdapter: Bluetooth binder is null
10-03 16:08:07.460 1349-1365/? E/KernelCpuSpeedReader: Failed to read cpu-freq
10-03 16:08:07.460 1349-1365/? E/KernelCpuSpeedReader: java.io.FileNotFoundException: /sys/devices/system/cpu/cpu0/cpufreq/stats/time_in_state: open failed: ENOENT (No such file or directory)`

为什么不起作用?

0 个答案:

没有答案