1

我有一个自定义相机应用程序,我正在尝试对其进行设置,以便用户可以触摸屏幕并将相机聚焦在他们触摸的地方。

我遇到的问题是,当我运行 if 语句时if(camParam.getMaxNumFocusAreas()>0){...},它遇到了空指针异常。

我首先尝试记录输出, Log.d(TAG, "max focus areas: "+camParam.getMaxNumFocusAreas()); 以防它只是因为某种原因而将其设置为 0,但这只是让它在那一行出现空指针异常。

有人知道为什么会发生这种情况吗?

如果我是盲人,只是看不到它在说什么,这里是导致异常的代码:

               Camera.Area area = new Camera.Area(new Rect(-500, -500, 500,500), 0);
                ArrayList<Camera.Area> listArea = new ArrayList<Camera.Area>();
                listArea.add(area);
                Log.d(TAG, "max focus areas: "+camParam.getMaxNumFocusAreas());
                if(camParam.getMaxNumFocusAreas()>0){
                    camParam.setFocusAreas(listArea);
                }
                Preview.camera.setParameters(camParam);

以及我的堆栈跟踪中的异常:

05-23 07:39:52.023    9780-9780/com.braindudecreations.tangets E/InputEventReceiver: Exception dispatching input event.
05-23 07:39:52.023    9780-9780/com.braindudecreations.tangets E/MessageQueue-JNI: Exception in MessageQueue callback: handleReceiveCallback
05-23 07:39:52.023    9780-9780/com.braindudecreations.tangets E/MessageQueue-JNI: java.lang.NullPointerException
        at com.braindudecreations.tangets.CameraDemo.onTouchEvent(CameraDemo.java:611)
        at android.app.Activity.dispatchTouchEvent(Activity.java:2413)
        at com.braindudecreations.tangets.CameraDemo.dispatchTouchEvent(CameraDemo.java:585)
        at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1901)
        at android.view.View.dispatchPointerEvent(View.java:7426)
        at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3220)
        at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3165)
        at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4292)
        at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4271)
        at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4363)
        at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:179)
        at android.os.MessageQueue.nativePollOnce(Native Method)
        at android.os.MessageQueue.next(MessageQueue.java:125)
        at android.os.Looper.loop(Looper.java:124)
        at android.app.ActivityThread.main(ActivityThread.java:5041)
        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:793)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
        at dalvik.system.NativeStart.main(Native Method)
4

0 回答 0