問一下,我做了一個攝像頭程序,繼承了一個SurfaceView做預覽,但用addView(mPreview)將預覽添加到FrameLayout時,
報錯說Unable to start activity ComponentInfo{com.example.test/com.example.test.CameraActivity}: java.lang.NullPointerException.
之前構造mPreview已經成功了,請問一下這是什麼問題?
代碼如下:
首先實現了
public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback ()
{
//實現了 public CameraPreview(Context context, Camera camera){}
public void surfaceCreated(SurfaceHolder holder) {}
public void surfaceDestroyed(SurfaceHolder holder) {}
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {}
}
然後在activity中調用時
mPreview = new CameraPreview(this, mCamera);
FrameLayout preview = (FrameLayout) findViewById(R.id.camerapreview);
preview.addView(mPreview);
問題出在preview.addView(mPreview);這句上,提示mPreview為空,請問是怎麼回事
http://blog.csdn.net/wellxy/article/details/7627956