Note that there are some explanatory texts on larger screens.

plurals
  1. POjava.lang.RuntimeException: Method call after release()
    primarykey
    data
    text
    <p>i have an android application which has two camera activities. they switch time to time in between them. after switching several times first activity throws this exception.. any idea why this happen? how to fix it? Please help me.thank you for reading my question and have a nice day!</p> <p><img src="https://i.stack.imgur.com/FrZou.jpg" alt="enter image description here"></p> <pre><code> public abstract class SampleViewBase extends SurfaceView implements SurfaceHolder.Callback, Runnable { private static final String TAG = "LogcatActivity"; private Camera mCamera; private SurfaceHolder mHolder; private int mFrameWidth; private int mFrameHeight; private byte[] mFrame; private boolean mThreadRun; private int frameNumber=1;//my public SampleViewBase(Context context) {/// super(context); mHolder = getHolder(); mHolder.addCallback(this); Log.i(TAG, "Instantiated new " + this.getClass()); } public int getFrameWidth() { return mFrameWidth; } public int getFrameHeight() { return mFrameHeight; } public void surfaceChanged(SurfaceHolder _holder, int format, int width, int height) { Log.i(TAG, "surfaceCreated"); if (mCamera != null) { Camera.Parameters params = mCamera.getParameters(); List&lt;Camera.Size&gt; sizes = params.getSupportedPreviewSizes(); //-- List&lt;String&gt; flashing_methords=params.getSupportedFlashModes(); params.setFlashMode(flashing_methords.get(3)); // List&lt;String&gt; color_effects=params.getSupportedColorEffects(); // params.setColorEffect(color_effects.get(2)); //-- mFrameWidth = width; mFrameHeight = height; // selecting optimal camera preview size { double minDiff = Double.MAX_VALUE; for (Camera.Size size : sizes) { if (Math.abs(size.height - height) &lt; minDiff) { mFrameWidth = size.width; mFrameHeight = size.height; minDiff = Math.abs(size.height - height); } } } params.setPreviewSize(getFrameWidth(), getFrameHeight()); mCamera.setParameters(params); mCamera.startPreview(); } } public void surfaceCreated(SurfaceHolder holder) { Log.i(TAG, "surfaceCreated"); try{ mCamera.reconnect(); mCamera = Camera.open(); mCamera.setPreviewCallback(new PreviewCallback() { public void onPreviewFrame(byte[] data, Camera camera) { synchronized (SampleViewBase.this) { mFrame = data; SampleViewBase.this.notify(); } /* if((frameNumber%120)==0){ synchronized (SampleViewBase.this) { mFrame = data; SampleViewBase.this.notify(); frameNumber=1; } }else{ frameNumber++; }*/ } }); (new Thread(this)).start(); }catch (Exception e) { Log.v(TAG, "reconnect error" + e); } } public void surfaceDestroyed(SurfaceHolder holder) { Log.i(TAG, "surfaceDestroyed"); mThreadRun = false; if (mCamera != null) { synchronized (this) { mCamera.stopPreview(); mCamera.setPreviewCallback(null); mCamera.release(); mCamera = null; } } } protected abstract Bitmap processFrame(byte[] data); public void run() { mThreadRun = true; Log.i(TAG, "Starting processing thread"); while (mThreadRun) { Bitmap bmp = null; synchronized (this) { try { this.wait(); bmp = processFrame(mFrame); } catch (InterruptedException e) { e.printStackTrace(); } } if (bmp != null) { Canvas canvas = mHolder.lockCanvas(); if (canvas != null) { canvas.drawBitmap(bmp, (canvas.getWidth() - getFrameWidth()) / 2, (canvas.getHeight() - getFrameHeight()) / 2, null); mHolder.unlockCanvasAndPost(canvas); } bmp.recycle(); } } } public void releaseAll() { Log.i(TAG, "hardweare released"); mThreadRun = false; if (mCamera != null) { synchronized (this) { mCamera.stopPreview(); mCamera.setPreviewCallback(null); mCamera.release(); mCamera = null; } } } </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload