PhotoView icon indicating copy to clipboard operation
PhotoView copied to clipboard

NullPointerException during setScale on commit 68464c72e6b6a58d90b9213206209367e6e0c05a

Open StingerAJ opened this issue 13 years ago • 2 comments

dev branch of PhotoView on commit 68464c72e6b6a58d90b9213206209367e6e0c05a

This is reproducable in our app if you use a viewpager and swipe to another page very quickly.

After that the callback from the asynchronous network loading-mechanism tries to update the PhotoView and set its scale.

My diagnosis:

It seems that the pagefragment that is gone cleans up the PhotoView and its PhotoViewAttacher by calling mAttacher.cleanup() in PhotoView. onDetachedFromWindow().

cleanup() nullifies the mImageView reference which is not checked in PhotoViewAttacher.setScale(float, boolean).

Stacktrace:

java.lang.NullPointerException
    at uk.co.senab.photoview.PhotoViewAttacher.setScale(PhotoViewAttacher.java:486)
    at uk.co.senab.photoview.PhotoViewAttacher.setScale(PhotoViewAttacher.java:481)
    at uk.co.senab.photoview.PhotoView.setScale(PhotoView.java:155)
    at de.billiger.android.products.gallery.ProductGalleryViewPagerActivity$ProductImageRequestListener.onRequestSuccess(ProductGalleryViewPagerActivity.java:191)
    at de.billiger.android.products.gallery.ProductGalleryViewPagerActivity$ProductImageRequestListener.onRequestSuccess(ProductGalleryViewPagerActivity.java:1)
    at com.octo.android.robospice.request.RequestProcessor$ResultRunnable.run(RequestProcessor.java:469)
    at android.os.Handler.handleCallback(Handler.java:615)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4898)
    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:1008)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775)
    at dalvik.system.NativeStart.main(Native Method)

My fix would be to check mImageView against null in setScale and simply return if it is null. I will send a pull request for this.

StingerAJ avatar Sep 10 '13 09:09 StingerAJ

Please, test current state of dev, your fix is probably not correct.

smarek avatar Sep 12 '13 14:09 smarek

Thank you very much for the bugfix! Closing this issue.

StingerAJ avatar Sep 13 '13 06:09 StingerAJ