问题描述
-
如果我是的不使用的 mCamera.release(); 中的的 surfaceDestroyed(....)的和的无法从另一个活动再次启动CameraActivity 的 [在短期获得的不幸的是应用程序已经停止]的错误, 即使不释放摄像机的,但如果的我做水龙头的主页按钮的[从CameraActivity ],然后 再次启动我的应用程序的,没有得到任何错误的(中短篇作品精致,开放CameraActivity没有任何问题)
-
和,如果我的的使用的 *的 mCamera.release(); 的*中的的 surfaceDestroyed(。 ...)的和的能够从另一个活动再次启动CameraActivity 的和的释放摄像头以及的,但的当我做轻触主页按钮,然后重新启动我的应用程序,让不幸的是应用程序已经停止的 ...
但我想两件事一起工作(第一, 轻按回家CameraActivity,再从CameraActivity启动应用程序的 - 没有任何错误)和(二的的从另一个活动启动相机的 - 没有任何错误)
就像我写的,这两个东西是为我工作,却不能在一起......
行号33是:
Camera.Parameters参数= mCamera.getParameters();
完整的日志:
12月12日至30号:18:58.070:W / dalvikvm(14822):主题ID = 1:螺纹退出与未捕获的异常(组= 0x41ef72a0)
十二月12号至30号:18:58.080:E / AndroidRuntime(14822):致命异常:主要
十二月12号至30号:18:58.080:E / AndroidRuntime(14822):java.lang.RuntimeException的:方法释放后称为()
十二月12号至30号:18:58.080:E / AndroidRuntime(14822):在android.hardware.Camera.native_getParameters(本机方法)
十二月12号至30号:18:58.080:E / AndroidRuntime(14822):在android.hardware.Camera.getParameters(Camera.java:1487)
十二月12号至30号:18:58.080:E / AndroidRuntime(14822):在app.micheal.camr previewSurface.surfaceCreated(previewSurface.java:33)。
十二月12号至30号:18:58.080:E / AndroidRuntime(14822):在android.view.SurfaceView.updateWindow(SurfaceView.java:609)
十二月12号至30号:18:58.080:E / AndroidRuntime(14822):在android.view.SurfaceView.onWindowVisibilityChanged(SurfaceView.java:235)
十二月12号至30号:18:58.080:E / AndroidRuntime(14822):在android.view.View.dispatchWindowVisibilityChanged(View.java:7686)
十二月12号至30号:18:58.080:E / AndroidRuntime(14822):在android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1047)
十二月12号至30号:18:58.080:E / AndroidRuntime(14822):在android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1047)
十二月12号至30号:18:58.080:E / AndroidRuntime(14822):在android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1047)
十二月12号至30号:18:58.080:E / AndroidRuntime(14822):在android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1047)
十二月12号至30号:18:58.080:E / AndroidRuntime(14822):在android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1047)
十二月12号至30号:18:58.080:E / AndroidRuntime(14822):在android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1339)
十二月12号至30号:18:58.080:E / AndroidRuntime(14822):在android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1114)
十二月12号至30号:18:58.080:E / AndroidRuntime(14822):在android.view.ViewRootImpl $ TraversalRunnable.run(ViewRootImpl.java:4520)
十二月12号至30号:18:58.080:E / AndroidRuntime(14822):在android.view.Choreographer $ CallbackRecord.run(Choreographer.java:725)
十二月12号至30号:18:58.080:E / AndroidRuntime(14822):在android.view.Choreographer.doCallbacks(Choreographer.java:555)
十二月12号至30号:18:58.080:E / AndroidRuntime(14822):在android.view.Choreographer.doFrame(Choreographer.java:525)
十二月12号至30号:18:58.080:E / AndroidRuntime(14822):在android.view.Choreographer $ FrameDisplayEventReceiver.run(Choreographer.java:711)
十二月12号至30号:18:58.080:E / AndroidRuntime(14822):在android.os.Handler.handleCallback(Handler.java:615)
十二月12号至30号:18:58.080:E / AndroidRuntime(14822):在android.os.Handler.dispatchMessage(Handler.java:92)
十二月12号至30号:18:58.080:E / AndroidRuntime(14822):在android.os.Looper.loop(Looper.java:137)
十二月12号至30号:18:58.080:E / AndroidRuntime(14822):在android.app.ActivityThread.main(ActivityThread.java:4921)
十二月12号至30号:18:58.080:E / AndroidRuntime(14822):在java.lang.reflect.Method.invokeNative(本机方法)
十二月12号至30号:18:58.080:E / AndroidRuntime(14822):在java.lang.reflect.Method.invoke(Method.java:511)
十二月12号至30号:18:58.080:E / AndroidRuntime(14822):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1036)
十二月12号至30号:18:58.080:E / AndroidRuntime(14822):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:803)
十二月12号至30号:18:58.080:E / AndroidRuntime(14822):在dalvik.system.NativeStart.main(本机方法)
十二月12号至30号:19:08.095:I /流程(14822):发送信号。 PID:14822 SIG:9
previewSurface.java:
公共类previewSurface延伸SurfaceView工具
SurfaceHolder.Callback {
公共静态最后弦乐LOG_TAG =相机preVIEW;
私人SurfaceHolder mSurfaceHolder;
私人相机mCamera;
Camera.Parameters参数= NULL;
//构造,其获得的上下文和摄像头
@燮pressWarnings(德precation)
公共previewSurface(上下文的背景下,相机摄像头){
超(上下文);
this.mCamera =摄像头;
this.mSurfaceHolder = this.getHolder();
this.mSurfaceHolder.addCallback(本);
this.mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
this.mSurfaceHolder.setFixedSize(100,100);
}
@覆盖
公共无效surfaceCreated(SurfaceHolder surfaceHolder){
尝试 {
参数= mCamera.getParameters();
如果(this.getResources()。getConfiguration()。方向!= Configuration.ORIENTATION_LANDSCAPE)
{
parameters.set(方向,肖像);
mCamera.setDisplayOrientation(90);
parameters.setRotation(90);
mCamera.set previewDisplay(surfaceHolder);
mCamera.start preVIEW();
}
其他
{
//这是一个无证虽然广为人知的功能
parameters.set(方向,山水);
//为Android 2.2及以上
mCamera.setDisplayOrientation(0);
//取消注释为Android 2.0及以上
parameters.setRotation(0);
}
mCamera.set previewDisplay(surfaceHolder);
mCamera.start preVIEW();
}赶上(IOException异常E){
//留空现在
}
}
@覆盖
公共无效surfaceDestroyed(SurfaceHolder surfaceHolder){
mCamera.stop preVIEW();
mCamera.release();
}
@覆盖
公共无效surfaceChanged(SurfaceHolder surfaceHolder,INT格式,
INT宽度,高度INT){
尝试 {
参数= mCamera.getParameters();
如果(this.getResources()。getConfiguration()。方向!= Configuration.ORIENTATION_LANDSCAPE){
parameters.set(方向,肖像);
mCamera.setDisplayOrientation(90);
parameters.setRotation(90);
}
其他 {
//这是一个无证虽然广为人知的功能
parameters.set(方向,山水);
//为Android 2.2及以上
mCamera.setDisplayOrientation(0);
//取消注释为Android 2.0及以上
parameters.setRotation(0);
}
mCamera.set previewDisplay(surfaceHolder);
mCamera.start preVIEW();
}赶上(IOException异常E){
//留空现在
}
}
}
试试这个,取代你的code与我,我想这会帮助你, 我还没有尝试过,但看起来会解决你的错误的
@覆盖
公共无效surfaceDestroyed(SurfaceHolder surfaceHolder){
this.getHolder()removeCallback(本)。
mCamera.stop preVIEW();
mCamera.release();
}
让我知道尽快...
If i am not using mCamera.release(); in surfaceDestroyed(....) then not able to launch CameraActivity again from another Activity [in short getting Unfortunately app has stopped] error, even not releasing Camera, but if i do tap on Home button [from CameraActivity], and then again launching my app, not getting any error (in short works fine, and opening CameraActivity without any problem)
And if i am using *mCamera.release();* in surfaceDestroyed(....) then able to launch CameraActivity again from another Activity and releasing Camera as well, but when i do tap on Home button, and then again launching my app, getting Unfortunately app has stopped....:
But i want both things working together (first, Tap on Home from CameraActivity, and again launch app from CameraActivity - without any error) and (second, launching camera from another activity - without any error)
Like i wrote, both the things are working for me, but not together.....
Line number 33 is:
Camera.Parameters parameters = mCamera.getParameters();
complete Log:
12-30 12:18:58.070: W/dalvikvm(14822): threadid=1: thread exiting with uncaught exception (group=0x41ef72a0)
12-30 12:18:58.080: E/AndroidRuntime(14822): FATAL EXCEPTION: main
12-30 12:18:58.080: E/AndroidRuntime(14822): java.lang.RuntimeException: Method called after release()
12-30 12:18:58.080: E/AndroidRuntime(14822): at android.hardware.Camera.native_getParameters(Native Method)
12-30 12:18:58.080: E/AndroidRuntime(14822): at android.hardware.Camera.getParameters(Camera.java:1487)
12-30 12:18:58.080: E/AndroidRuntime(14822): at app.micheal.camr.PreviewSurface.surfaceCreated(PreviewSurface.java:33)
12-30 12:18:58.080: E/AndroidRuntime(14822): at android.view.SurfaceView.updateWindow(SurfaceView.java:609)
12-30 12:18:58.080: E/AndroidRuntime(14822): at android.view.SurfaceView.onWindowVisibilityChanged(SurfaceView.java:235)
12-30 12:18:58.080: E/AndroidRuntime(14822): at android.view.View.dispatchWindowVisibilityChanged(View.java:7686)
12-30 12:18:58.080: E/AndroidRuntime(14822): at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1047)
12-30 12:18:58.080: E/AndroidRuntime(14822): at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1047)
12-30 12:18:58.080: E/AndroidRuntime(14822): at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1047)
12-30 12:18:58.080: E/AndroidRuntime(14822): at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1047)
12-30 12:18:58.080: E/AndroidRuntime(14822): at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1047)
12-30 12:18:58.080: E/AndroidRuntime(14822): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1339)
12-30 12:18:58.080: E/AndroidRuntime(14822): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1114)
12-30 12:18:58.080: E/AndroidRuntime(14822): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4520)
12-30 12:18:58.080: E/AndroidRuntime(14822): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
12-30 12:18:58.080: E/AndroidRuntime(14822): at android.view.Choreographer.doCallbacks(Choreographer.java:555)
12-30 12:18:58.080: E/AndroidRuntime(14822): at android.view.Choreographer.doFrame(Choreographer.java:525)
12-30 12:18:58.080: E/AndroidRuntime(14822): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
12-30 12:18:58.080: E/AndroidRuntime(14822): at android.os.Handler.handleCallback(Handler.java:615)
12-30 12:18:58.080: E/AndroidRuntime(14822): at android.os.Handler.dispatchMessage(Handler.java:92)
12-30 12:18:58.080: E/AndroidRuntime(14822): at android.os.Looper.loop(Looper.java:137)
12-30 12:18:58.080: E/AndroidRuntime(14822): at android.app.ActivityThread.main(ActivityThread.java:4921)
12-30 12:18:58.080: E/AndroidRuntime(14822): at java.lang.reflect.Method.invokeNative(Native Method)
12-30 12:18:58.080: E/AndroidRuntime(14822): at java.lang.reflect.Method.invoke(Method.java:511)
12-30 12:18:58.080: E/AndroidRuntime(14822): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1036)
12-30 12:18:58.080: E/AndroidRuntime(14822): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:803)
12-30 12:18:58.080: E/AndroidRuntime(14822): at dalvik.system.NativeStart.main(Native Method)
12-30 12:19:08.095: I/Process(14822): Sending signal. PID: 14822 SIG: 9
PreviewSurface.java:
public class PreviewSurface extends SurfaceView implements
SurfaceHolder.Callback {
public static final String LOG_TAG = "CameraPreview";
private SurfaceHolder mSurfaceHolder;
private Camera mCamera;
Camera.Parameters parameters = null ;
// Constructor that obtains context and camera
@SuppressWarnings("deprecation")
public PreviewSurface(Context context, Camera camera) {
super(context);
this.mCamera = camera;
this.mSurfaceHolder = this.getHolder();
this.mSurfaceHolder.addCallback(this);
this.mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
this.mSurfaceHolder.setFixedSize(100, 100);
}
@Override
public void surfaceCreated(SurfaceHolder surfaceHolder) {
try {
parameters = mCamera.getParameters();
if (this.getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE)
{
parameters.set("orientation", "portrait");
mCamera.setDisplayOrientation(90);
parameters.setRotation(90);
mCamera.setPreviewDisplay(surfaceHolder);
mCamera.startPreview();
}
else
{
// This is an undocumented although widely known feature
parameters.set("orientation", "landscape");
// For Android 2.2 and above
mCamera.setDisplayOrientation(0);
// Uncomment for Android 2.0 and above
parameters.setRotation(0);
}
mCamera.setPreviewDisplay(surfaceHolder);
mCamera.startPreview();
} catch (IOException e) {
// left blank for now
}
}
@Override
public void surfaceDestroyed(SurfaceHolder surfaceHolder) {
mCamera.stopPreview();
mCamera.release();
}
@Override
public void surfaceChanged(SurfaceHolder surfaceHolder, int format,
int width, int height) {
try {
parameters = mCamera.getParameters();
if (this.getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE) {
parameters.set("orientation", "portrait");
mCamera.setDisplayOrientation(90);
parameters.setRotation(90);
}
else {
// This is an undocumented although widely known feature
parameters.set("orientation", "landscape");
// For Android 2.2 and above
mCamera.setDisplayOrientation(0);
// Uncomment for Android 2.0 and above
parameters.setRotation(0);
}
mCamera.setPreviewDisplay(surfaceHolder);
mCamera.startPreview();
} catch (IOException e) {
// left blank for now
}
}
}
try this, replace your code with mine, i guess this will help you, i have not tried but looks it will resolve your errors
@Override
public void surfaceDestroyed(SurfaceHolder surfaceHolder) {
this.getHolder().removeCallback(this);
mCamera.stopPreview();
mCamera.release();
}
Let me know ASAP...
这篇关于java.lang.RuntimeException的:方法释放后称为()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!