0

我正在尝试使用我的应用程序录制视频,但是当我单击录制按钮时,它会在Camera.Parameters params = mCamera.getParameters();. 我搜索了很多,但找到了一种解决方案,例如camera.open()但在我的情况下也不起作用。我的手机有后置摄像头,所以我也尝试了 camera.open(0) 或 camera.open(1) 但没有任何帮助。

这是我的代码供您参考。

@Override
public void onCreate(Bundle savedInstanceState) {
    //mCamera = Camera.open(0);
     if (mCamera == null) {
    mCamera = getCameraInstance();
    // Create preview view and set it as the content of our activity.
    mPreview = new CameraPreview(this, mCamera);
    } else {
        mCamera.release();
        mCamera = getCameraInstance();

        mPreview = new CameraPreview(this, mCamera);     
        }
      int i = R.id.videoFrameView;
        Object o = this.findViewById(i);
        final FrameLayout preview = (FrameLayout) o;            

        preview.addView(mPreview);
        //mCamera = Camera.open(1);
        Camera.Parameters params = mCamera.getParameters();
   // Here i am getting nullpointer exception. 
        params.set("cam_mode", 1);
        mCamera.setParameters(params);

        sizes = params.getSupportedPreviewSizes();   

这是我的logacat。

04-23 19:21:27.642: E/AndroidRuntime(25598): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.aml.videoaml/com.aml.videoaml.RecordActivity}: java.lang.NullPointerException
04-23 19:21:27.642: E/AndroidRuntime(25598):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2077)
04-23 19:21:27.642: E/AndroidRuntime(25598):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2104)
04-23 19:21:27.642: E/AndroidRuntime(25598):    at android.app.ActivityThread.access$600(ActivityThread.java:134)
04-23 19:21:27.642: E/AndroidRuntime(25598):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1247)
04-23 19:21:27.642: E/AndroidRuntime(25598):    at android.os.Handler.dispatchMessage(Handler.java:99)
04-23 19:21:27.642: E/AndroidRuntime(25598):    at android.os.Looper.loop(Looper.java:154)
04-23 19:21:27.642: E/AndroidRuntime(25598):    at android.app.ActivityThread.main(ActivityThread.java:4624)
04-23 19:21:27.642: E/AndroidRuntime(25598):    at java.lang.reflect.Method.invokeNative(Native Method)
04-23 19:21:27.642: E/AndroidRuntime(25598):    at java.lang.reflect.Method.invoke(Method.java:511)
04-23 19:21:27.642: E/AndroidRuntime(25598):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:809)
04-23 19:21:27.642: E/AndroidRuntime(25598):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576)
04-23 19:21:27.642: E/AndroidRuntime(25598):    at dalvik.system.NativeStart.main(Native Method)
04-23 19:21:27.642: E/AndroidRuntime(25598): Caused by: java.lang.NullPointerException
04-23 19:21:27.642: E/AndroidRuntime(25598):    at com.aml.videoaml.RecordActivity.onCreate(RecordActivity.java:63)
04-23 19:21:27.642: E/AndroidRuntime(25598):    at android.app.Activity.performCreate(Activity.java:4479)
04-23 19:21:27.642: E/AndroidRuntime(25598):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1050)
04-23 19:21:27.642: E/AndroidRuntime(25598):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2041)
04-23 19:21:27.642: E/AndroidRuntime(25598):  

我不明白我的代码有什么问题,请给我任何参考或提示。
谢谢

4

1 回答 1

0

如果由于某种原因未释放相机或应用程序崩溃,则您可能无法打开相机。我不确定您的情况,但您也可以考虑这种可能性。在这种情况下,重新启动设备将起作用。

于 2013-04-23T14:01:00.210 回答