getParameters失败(空参数)Android:

时间:2014-09-10 06:07:59

标签: android android-camera android-video-player android-videoview

我在我的应用程序中使用相机,它在我的应用程序中正常工作。但是我们已经在root平板电脑上测试了所有应用程序都被剥离了平板电脑,包括原生媒体库。现在的问题是,当我们尝试从这些有根据的平板电脑应用视频时会崩溃。我有以下堆栈跟踪:

java.lang.RuntimeException: getParameters failed (empty parameters)
       at android.hardware.Camera.native_getParameters(Camera.java)
       at android.hardware.Camera.getParameters(Camera.java:1464)
       at com.x.y.video.Preview.onTouchEvent(Preview.java:404)
       at android.view.View.dispatchTouchEvent(View.java:7392)
       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2235)
       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1978)
       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2235)
       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1978)
       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2235)
       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1978)
       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2235)
       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1978)
       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2235)
       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1978)
       at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2177)
       at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1482)
       at android.app.Activity.dispatchTouchEvent(Activity.java:2483)
       at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2125)
       at android.view.View.dispatchPointerEvent(View.java:7577)
       at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3376)
       at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3308)
       at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4421)
       at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4399)
       at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4505)
       at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:178)
       at android.os.MessageQueue.nativePollOnce(MessageQueue.java)
       at android.os.MessageQueue.next(MessageQueue.java:125)
       at android.os.Looper.loop(Looper.java:124)
       at android.app.ActivityThread.main(ActivityThread.java:4949)
       at java.lang.reflect.Method.invokeNative(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:511)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1043)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:810)
       at dalvik.system.NativeStart.main(NativeStart.java)

这表明以下行中的错误

Camera.Parameters parameters = camera.getParameters();

我该如何解决这个问题。请有人帮帮我。

我在StackOverFlow中发现了类似这样的问题,但没有解决方案适合我。

修改 我添加了示例代码

if( camera != null && !this.using_face_detection ) {
            Camera.Parameters parameters = camera.getParameters();
            String focus_mode = parameters.getFocusMode();
            this.has_focus_area = false;
            // getFocusMode() is documented as never returning null, however I've had null pointer exceptions reported in Google Play
            if( parameters.getMaxNumFocusAreas() != 0 && focus_mode != null && ( focus_mode.equals(Camera.Parameters.FOCUS_MODE_AUTO) || focus_mode.equals(Camera.Parameters.FOCUS_MODE_MACRO) || focus_mode.equals(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE) || focus_mode.equals(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO) ) ) {
                if( MyDebug.LOG )
                    Log.d(TAG, "set focus (and metering?) area");
                this.has_focus_area = true;
                this.focus_screen_x = (int)event.getX();
                this.focus_screen_y = (int)event.getY();

                ArrayList<Camera.Area> areas = getAreas(event.getX(), event.getY());
                parameters.setFocusAreas(areas);

                // also set metering areas
                if( parameters.getMaxNumMeteringAreas() == 0 ) {
                    if( MyDebug.LOG )
                        Log.d(TAG, "metering areas not supported");
                }
                else {
                    parameters.setMeteringAreas(areas);
                }

                setCameraParameters(parameters);
            }
            else if( parameters.getMaxNumMeteringAreas() != 0 ) {
                if( MyDebug.LOG )
                    Log.d(TAG, "set metering area");
                // don't set has_focus_area in this mode
                ArrayList<Camera.Area> areas = getAreas(event.getX(), event.getY());
                parameters.setMeteringAreas(areas);

                setCameraParameters(parameters);
            }
        }

0 个答案:

没有答案