Take Picture failed android
<p>I have this code and they show to me an error "java.lang.RuntimeException: takePicture failed" when i click on snapit button to tack photo.
i try the code it was work before cable months</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>vpublic class TackPhoto extends AppCompatActivity {
//    SurfaceView cameraView;
    customSurfaceView surfaceView;
//    SurfaceHolder surfaceHolder;
    Camera camera;
    Button flipCamera;
    Button snapPhoto ;
    int cameraID = 0;

    private Camera.PictureCallback capturedIt = new Camera.PictureCallback(){

        @Override
        public void onPictureTaken(byte[] data, Camera camera) {
            Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
            if (bitmap == null){
                Toast.makeText(getApplicationContext(), "not taken", Toast.LENGTH_SHORT).show();
            }else {
                .
                .
                .
                .

                Toast.makeText(getApplicationContext(), "taken",Toast.LENGTH_SHORT).show();

            }
            camera.release();
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tack_photo);

        try {
            camera = Camera.open(cameraID);
        }
        catch (Exception e){
        }
        surfaceView = new customSurfaceView(this,camera);
        FrameLayout preview = (FrameLayout) findViewById(R.id.camera_preview);

        preview.addView(surfaceView);


        snapPhoto = (Button)findViewById(R.id.snapPhoto);
        snapPhoto.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                camera.takePicture(null,null,capturedIt);
            }
        });
    }

}</code></pre>
</div>
</div>
</p>

<p>this the class for previwing
<div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code> public class customSurfaceView extends SurfaceView implements SurfaceHolder.Callback, Camera.PreviewCallback {

            private Camera camera;
            //private SurfaceHolder surfaceHolder;
            private SurfaceHolder surfaceHolder;
            private Context context;
            boolean previewing = false;


   
            @Override
            public void surfaceCreated(SurfaceHolder holder) {


                try
                {
                    camera = Camera.open(cameraID);
                    camera.setPreviewDisplay(holder);
                }
                catch (IOException exception)
                {
                    camera.release();
                }

                camera.startPreview();
                previewing = true;

            }

            @Override
            public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
                if(previewing){
                    camera.stopPreview();
                    previewing = false;
                }

                if (camera != null){
                    try {
                        camera.setPreviewDisplay(holder);
                        Display display = ((WindowManager)getApplicationContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();

                        if(display.getRotation() == Surface.ROTATION_0)
                        {
                            camera.setDisplayOrientation(90);
                        }
                        if(display.getRotation() == Surface.ROTATION_270)
                        {
                            camera.setDisplayOrientation(180);
                        }

                        camera.startPreview();
                        previewing = true;

                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }

            }

            @Override
            public void surfaceDestroyed(SurfaceHolder holder) {

                camera.stopPreview();
                if (camera != null)
                    camera.release();
                camera=null;

            }

            public void flipit(){
                camera.stopPreview();
                camera.release();

                if (cameraID == 0){
                    camera = Camera.open(1);
                    cameraID = 1;
                }else {
                    camera = Camera.open(0);
                    cameraID = 0;
                }
                try
                {

                    camera.setPreviewDisplay(surfaceHolder);
                    camera.setPreviewCallback(this);
                    if (camera != null){
                        try {
                            camera.setPreviewDisplay(surfaceHolder);
                            Display display = ((WindowManager)getApplicationContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();

                            if(display.getRotation() == Surface.ROTATION_0)
                            {
                                camera.setDisplayOrientation(90);
                            }
                            if(display.getRotation() == Surface.ROTATION_270)
                            {
                                camera.setDisplayOrientation(180);
                            }

                            //camera.startPreview();
                            camera.startPreview();
                            previewing = true;

                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
                }
                catch (IOException exception)
                {
                    camera.release();
                }



            }

            @Override
            public void onPreviewFrame(byte[] data, Camera camera) {

            }
        }</code></pre>
</div>
</div>
</p>

<p>logcat output</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>    E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                                 Process: com.example.abcd.abcd.abcd.abcd, PID: 12272
                                                                                                 Theme: themes:{}
                                                                                                 java.lang.RuntimeException: takePicture failed
                                                                                                     at android.hardware.Camera.native_takePicture(Native Method)
                                                                                                     at android.hardware.Camera.takePicture(Camera.java:1492)
                                                                                                     at android.hardware.Camera.takePicture(Camera.java:1436)
                                                                                                     at com.example.abcd.abcd.abcd.abcd.TackPhoto$3.onClick(TackPhoto.java:170)
                                                                                                     at android.view.View.performClick(View.java:5204)
                                                                                                     at android.view.View$PerformClick.run(View.java:21158)
                                                                                                     at android.os.Handler.handleCallback(Handler.java:739)
                                                                                                     at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                                                     at android.os.Looper.loop(Looper.java:148)
                                                                                                     at android.app.ActivityThread.main(ActivityThread.java:5461)
                                                                                                     at java.lang.reflect.Method.invoke(Native Method)
                                                                                                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)</code></pre>
</div>
</div>
</p>