简体   繁体   English

Galaxy Nexus上的LED手电筒:应用程序传递了NULL表面

[英]LED Flashlight on Galaxy Nexus: app passed NULL surface

I've been trying to get the LED flashlight come on on my Galaxy Nexus, using several different solutions on StackOverflow: 我一直在尝试使用StackOverflow上的几种不同解决方案将LED手电筒装在我的Galaxy Nexus上:

LED flashlight on Galaxy Nexus controllable by what API? Galaxy Nexus上的LED手电可由什么API控制?

Opening Flashlight of Galaxy Nexus 打开Galaxy Nexus的手电筒

But I'm still getting this error, and I cannot see why: 但是我仍然收到此错误,我看不到为什么:

Camera: app passed NULL surface 相机:应用程序传递了NULL曲面

This is my code (or rather the code from other solutions edited slightly): 这是我的代码(或者是来自其他解决方案的代码,经过稍微编辑):

package com.quinny898.doorcontrol;

import java.io.IOException;

import android.app.Activity;
import android.hardware.Camera;
import android.hardware.Camera.Parameters;
import android.os.Bundle;
import android.view.SurfaceHolder;
import android.view.SurfaceHolder.Callback;
import android.view.SurfaceView;

public class DoorControlDoing extends Activity implements Callback {
public Camera mCamera;

  /** Called when the activity is first created. */

  public void onCreate(Bundle savedInstanceState) {
      setContentView(R.layout.dialog_surface);
      SurfaceView preview = (SurfaceView) findViewById(R.id.surface_view);
      SurfaceHolder mHolder = preview.getHolder();
      mHolder.addCallback(this);


      super.onCreate(savedInstanceState);
      setContentView(R.layout.dialog_surface);
      Camera mCamera = Camera.open();
      Parameters params = mCamera.getParameters();
      params.setFlashMode(Parameters.FLASH_MODE_TORCH);
      mCamera.setParameters(params);      
      mCamera.startPreview();
      try {
            mCamera.setPreviewDisplay(mHolder);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        }




public void surfaceChanged(SurfaceHolder holder, int format, int width,
        int height) {}

public void surfaceCreated(SurfaceHolder holder) {
    setContentView(R.layout.dialog_surface);
    SurfaceView preview = (SurfaceView) findViewById(R.id.surface_view);
      SurfaceHolder mHolder = preview.getHolder();
    mHolder = holder;
    try {
        mCamera.setPreviewDisplay(mHolder);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

public void surfaceDestroyed(SurfaceHolder holder) {
    setContentView(R.layout.dialog_surface);
    SurfaceView preview = (SurfaceView) findViewById(R.id.surface_view);
      SurfaceHolder mHolder = preview.getHolder();
    mCamera.stopPreview();
    mHolder = null;
}
}

And this is the layout xml: 这是布局xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    <SurfaceView
    android:id="@+id/surface_view"
    android:layout_width="1px"
    android:layout_height="1px"/>
<TextView android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:text="@string/hi"/>
</LinearLayout>

I cannot see what is wrong here, all the IDs are correct and it inflates the layout fine, so why is it "NULL"? 我看不到这里出了什么问题,所有的ID都是正确的,并且会放大布局,那么为什么它是“ NULL”呢?

Thanks for any help! 谢谢你的帮助!

@Override

 public void surfaceCreated(SurfaceHolder holder) {

    try {
        camera.setPreviewDisplay(holder);
    } catch (Exception e) {

        e.printStackTrace();
    }
}
camera is
camera=Camera.open();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM