'android.view.surfaceholder Android.view.surfaceview.getholder()' On A Null Object Reference In Surfaceview
I am trying to show a camera preview in a dialogue. Every time I try to run the app I have the following error: java.lang.RuntimeException: Unable to start activity ComponentInfo{c
Solution 1:
change camera class to this:
public class CameraExample extends AnimatedViewContainer {
privatefinalstaticStringTAG="CameraExample";
private Context mContext;
private SurfaceView mPreview;
publicCameraExample(Context context, int i) {
super(context, i);
mContext = context;
}
@OverridepublicvoidonCreateViewContent(LayoutInflater layoutInflater, ViewGroup parentGroup, View[] containerViews, int index) {
containerViews[index] = layoutInflater.inflate(R.layout.example_camera, parentGroup, false);
FrameLayoutpreviewFrame= (FrameLayout) containerViews[index].findViewById(R.id.preview);
//this have been line moved here from constructor
mPreview = (SurfaceView) findViewById(R.id.surfaceView);
CameraPreviewmgr=newCameraPreview(mContext, mPreview);
mgr.init();
// Add preview for inflation
previewFrame.addView(mPreview);
}
}
Post a Comment for "'android.view.surfaceholder Android.view.surfaceview.getholder()' On A Null Object Reference In Surfaceview"