martinwithaar / PinchToZoom

Android's ImageView pinch-to-zoom made easy
MIT License
110 stars 27 forks source link

Fatal Exception: java.lang.NullPointerException #7

Open Duna opened 6 years ago

Duna commented 6 years ago
Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.drawable.Drawable.getIntrinsicWidth()' on a null object reference
       at com.bogdwellers.pinchtozoom.ImageMatrixCorrector.getInnerFitScale(ImageMatrixCorrector.java:62)
       at com.bogdwellers.pinchtozoom.ImageMatrixTouchHandler$ImageGestureListener.onDoubleTapEvent(ImageMatrixTouchHandler.java:430)
       at android.view.GestureDetector.onTouchEvent(GestureDetector.java:525)
       at com.bogdwellers.pinchtozoom.ImageMatrixTouchHandler.onTouch(ImageMatrixTouchHandler.java:326)
       at android.view.View.dispatchTouchEvent(View.java:8582)
       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2530)
       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2110)
       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2530)
       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2110)
       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2530)
       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2110)
       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2530)
       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2110)
       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2530)
       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2110)
       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2530)
       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2110)
       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2530)
       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2110)
       at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2538)
       at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1811)
       at android.app.Activity.dispatchTouchEvent(Activity.java:2820)
       at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:68)
       at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2476)
       at android.view.View.dispatchPointerEvent(View.java:8799)
       at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4729)
       at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4551)
       at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4047)
       at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4106)
       at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4066)
       at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4209)
       at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4074)
       at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4266)
       at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4047)
       at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4106)
       at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4066)
       at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4074)
       at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4047)
       at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:6530)
       at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:6504)
       at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:6457)
       at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:6689)
       at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:218)
       at android.os.MessageQueue.nativePollOnce(MessageQueue.java)
       at android.os.MessageQueue.next(MessageQueue.java:148)
       at android.os.Looper.loop(Looper.java:168)
       at android.app.ActivityThread.main(ActivityThread.java:5657)
       at java.lang.reflect.Method.invoke(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:372)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:990)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:785)
numanbutt777 commented 5 years ago

Any update to solve this java.lang.NullPointerException ???????

raviganwal commented 4 years ago

I know I am last at the party, but If anyone is still facing this error you need to set imageView.setOnTouchListener(new ImageMatrixTouchHandler(getApplicationContext())); when resource is ready,

        GlideApp
                .with(this)
                .load(image)
                .thumbnail(0.5f)
                .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)
                .listener(new RequestListener<Drawable>() {
                    @Override
                    public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
                        return false;
                    }

                    @Override
                    public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
                        imageView.setOnTouchListener(new ImageMatrixTouchHandler(getApplicationContext()));

                        return false;
                    }
                })
                .fitCenter()
                .error(R.drawable.no_image)
                .into(imageView);