camera-preview icon indicating copy to clipboard operation
camera-preview copied to clipboard

NullPointerException: Attempt to invoke virtual method 'boolean android.widget.FrameLayout.dispatchTouchEvent(android.view.MotionEvent)' on a null object reference

Open ghost opened this issue 2 years ago • 3 comments

Describe the bug NullPointerException for Android when "toBack" is set to true.

NullPointerException: Attempt to invoke virtual method 'boolean android.widget.FrameLayout.dispatchTouchEvent(android.view.MotionEvent)' on a null object reference

To Reproduce Steps to reproduce the behavior:

  1. Integrate this plugin
  2. Set "toBack" to true
  3. Running app
  4. When opening a screen that is invoking start of camera preview and user immediately clicks on screen when camera is not finished launching, app crashes

Expected behavior

App does not crash when clicking to early on screen..

Additional context

In the CameraPreview -> setupBroadcast method we invoke fragment.frameContainerLayout.dispatchTouchEvent(event); This will crash when fragment.frameContainerLayout is null. This is not being checked accordingly. Please, check the current method below.

I think, there should be (null != fragment.frameContainerLayout) added to the if statement.

 private void setupBroadcast() {
        /** When touch event is triggered, relay it to camera view if needed so it can support pinch zoom */

        getBridge().getWebView().setClickable(true);
        getBridge()
            .getWebView()
            .setOnTouchListener(
                new View.OnTouchListener() {
                    @Override
                    public boolean onTouch(View v, MotionEvent event) {
                        if ((null != fragment) && (fragment.toBack == true)) {
                            fragment.frameContainerLayout.dispatchTouchEvent(event);
                        }
                        return false;
                    }
                }
            );
    }

ghost avatar Jan 11 '23 11:01 ghost

I have the same issue, it's pretty annoying

DayUx avatar May 05 '23 12:05 DayUx

Can confirm that this works for us!

nvahalik avatar Sep 18 '23 14:09 nvahalik

Thanks this condition fixed the issue. But I am unable to reproduce this issue. It happens sometime, I don't know why. Please comment on this thread if anyone finds the root cause.

tradingproject19 avatar Mar 06 '24 15:03 tradingproject19