索尼Xperia M takePicture()总是崩溃

时间:2015-03-01 05:57:03

标签: android sony-xperia

我正在为Sony Xperia M C1905建造一个相机应用程序 用户按一个按钮拍照然后保存 当我在autoFocusCallback

之外调用takePicture()时问题开始

这是索尼特有的问题还是我在这里做错了什么?

这是logcat输出:

STACK_TRACE=java.lang.IllegalStateException:+Could+not+execute+method+of+the+activity
    at+android.view.View$1.onClick(View.java:3671)
    at+android.view.View.performClick(View.java:4171)
    at+android.view.View$PerformClick.run(View.java:17195)
    at+android.os.Handler.handleCallback(Handler.java:643)
    at+android.os.Handler.dispatchMessage(Handler.java:92)
    at+android.os.Looper.loop(Looper.java:137)
    at+android.app.ActivityThread.main(ActivityThread.java:4803)
    at+java.lang.reflect.Method.invokeNative(Native+Method)
    at+java.lang.reflect.Method.invoke(Method.java:511)
    at+com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
    at+com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
    at+dalvik.system.NativeStart.main(Native+Method)
Caused+by:+java.lang.reflect.InvocationTargetException
    at+java.lang.reflect.Method.invokeNative(Native+Method)
    at+java.lang.reflect.Method.invoke(Method.java:511)
    at+android.view.View$1.onClick(View.java:3666)
    ...+11+more
Caused+by:+java.lang.RuntimeException:+takePicture+failed
    at+android.hardware.Camera.native_takePicture(Native+Method)
    at+android.hardware.Camera.takePicture(Camera.java:1117)
    at+ims.alpha.moses.MainActivity.camerabuttonClicked(MainActivity.java:221)
    ...+14+more
java.lang.RuntimeException:+takePicture+failed
    at+android.hardware.Camera.native_takePicture(Native+Method)
    at+android.hardware.Camera.takePicture(Camera.java:1117)
    at+ims.alpha.moses.MainActivity.camerabuttonClicked(MainActivity.java:221)
    at+java.lang.reflect.Method.invokeNative(Native+Method)
    at+java.lang.reflect.Method.invoke(Method.java:511)
    at+android.view.View$1.onClick(View.java:3666)
    at+android.view.View.performClick(View.java:4171)
    at+android.view.View$PerformClick.run(View.java:17195)
    at+android.os.Handler.handleCallback(Handler.java:643)
    at+android.os.Handler.dispatchMessage(Handler.java:92)
    at+android.os.Looper.loop(Looper.java:137)
    at+android.app.ActivityThread.main(ActivityThread.java:4803)
    at+java.lang.reflect.Method.invokeNative(Native+Method)
    at+java.lang.reflect.Method.invoke(Method.java:511)
    at+com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
    at+com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
    at+dalvik.system.NativeStart.main(Native+Method)
&PHONE_MODEL=C1905&ANDROID_VERSION=4.1.2

以下是相关代码:

public PictureCallback jpgCallback = new PictureCallback() {            
    @Override
    public void onPictureTaken(byte[] data, Camera camera) {
    // do processing here
    }
};

// Sony Xperia M device constantly crash when takepicture is called from outside AutoFocusCallback
public AutoFocusCallback autoFocusCB = new AutoFocusCallback() {        
    public void onAutoFocus(boolean success, Camera camera) {
        if (success) {
            Globals.myCamera.takePicture(null, null, jpgCallback);
        } else {

        }
    }
};

此代码有效:

public void camerabuttonClicked(View v) {
    Globals.myCamera.setPreviewCallback(null);      
    Globals.myCamera.autoFocus(autoFocusCB);
}

此代码不断崩溃应用程序:

public void camerabuttonClicked(View v) {
    Globals.myCamera.stopPreview();     
    Globals.myCamera.takePicture(null, null, jpgCallback); // MainActivity.java:221
}

我还在三星Galaxy S2上测试了这个代码,它没有这个问题。我从哪里调用takePicture()并不重要。

0 个答案:

没有答案