0

while open camera feature in android it has throw an error of Null pointer exception and is redirecting to this line "camera.setPreviewDisplay(holder);"

What to do ?

Preview file : public void surfaceCreated(SurfaceHolder holder) {

    try {
        camera = Camera.open();

    } catch (Exception e) {
        Log.e("CameraVideoPOC", "failed to open Camera");
        e.printStackTrace();
    }

    try {
        camera.setPreviewDisplay(holder); // facing issue here
        camera.setPreviewCallback(new Camera.PreviewCallback() {

            public void onPreviewFrame(byte[] data, Camera arg1) {
                FileOutputStream outStream = null;
                try {
                    outStream = new FileOutputStream(String.format(
                            "/sdcard/%d.jpg", System.currentTimeMillis()));
                    outStream.write(data);
                    outStream.close();
                    Log.d(TAG, "onPreviewFrame - wrote bytes: "
                            + data.length);
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                } finally {
                }
                Preview.this.invalidate();
            }
        });
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Shashi
  • 1
  • 2
  • did you properly instantiated the holder obj ? – bijaykumarpun May 14 '19 at 09:12
  • Have you given the permission for camera in manifest? – sanjeev May 14 '19 at 09:29
  • Yes, i had given the permission on manifest. and had debug the holder obj and it is fine. but dont find the exact solution, can someone find me the solution as well. – Shashi May 14 '19 at 14:25
  • Possible duplicate of [What is a NullPointerException, and how do I fix it?](https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – Ricardo A. May 15 '19 at 13:42

0 Answers0