Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImageView no longer exists. You should not use this PhotoViewAttacher any more. #50

Closed
fanei opened this issue May 2, 2013 · 17 comments

Comments

@fanei
Copy link

fanei commented May 2, 2013

05-02 17:21:59.583: E/AndroidRuntime(6325): FATAL EXCEPTION: main
05-02 17:21:59.583: E/AndroidRuntime(6325): java.lang.IllegalStateException: ImageView no longer exists. You should not use this PhotoViewAttacher any more.
05-02 17:21:59.583: E/AndroidRuntime(6325): at com.yijian.app.view.photoview.PhotoViewAttacher.getImageView(PhotoViewAttacher.java:210)
05-02 17:21:59.583: E/AndroidRuntime(6325): at com.yijian.app.view.photoview.PhotoViewAttacher.update(PhotoViewAttacher.java:482)
05-02 17:21:59.583: E/AndroidRuntime(6325): at com.yijian.app.view.photoview.PhotoView.setImageDrawable(PhotoView.java:114)
05-02 17:21:59.583: E/AndroidRuntime(6325): at android.widget.ImageView.setImageBitmap(ImageView.java:377)
05-02 17:21:59.583: E/AndroidRuntime(6325): at com.yijian.app.activity.GalleryActivity$TestAdapter$1.onLoadingComplete(GalleryActivity.java:287)
05-02 17:21:59.583: E/AndroidRuntime(6325): at com.nostra13.universalimageloader.core.DisplayBitmapTask.run(DisplayBitmapTask.java:64)
05-02 17:21:59.583: E/AndroidRuntime(6325): at android.os.Handler.handleCallback(Handler.java:605)
05-02 17:21:59.583: E/AndroidRuntime(6325): at android.os.Handler.dispatchMessage(Handler.java:92)
05-02 17:21:59.583: E/AndroidRuntime(6325): at android.os.Looper.loop(Looper.java:137)
05-02 17:21:59.583: E/AndroidRuntime(6325): at android.app.ActivityThread.main(ActivityThread.java:4424)
05-02 17:21:59.583: E/AndroidRuntime(6325): at java.lang.reflect.Method.invokeNative(Native Method)
05-02 17:21:59.583: E/AndroidRuntime(6325): at java.lang.reflect.Method.invoke(Method.java:511)
05-02 17:21:59.583: E/AndroidRuntime(6325): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
05-02 17:21:59.583: E/AndroidRuntime(6325): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
05-02 17:21:59.583: E/AndroidRuntime(6325): at dalvik.system.NativeStart.main(Native Method)

@httpdispatch
Copy link
Contributor

This is weird behaviour caused by ImageView WeakReference in PhotoViewAttacher. Weird it is because system decides that ImageView is no more accessible from anywhere and clean the reference

Chris, isn't it strange that you call

imageView.setImageDrawable

but iside that method getImageView throws ImageView no longer exists?

@ened
Copy link

ened commented Aug 29, 2013

@chrisbanes This change hasn't made it into the maven central release, right?

@JayH5
Copy link

JayH5 commented Sep 1, 2013

Unfortunately it seems that Chris hasn't worked on this project in a while :(
Even when using PhotoView instead of attaching to an ImageView I have seen cases when this ISE is thrown. The above commit by Chris was necessary for me to get the library to work reliably.

@ened
Copy link

ened commented Sep 1, 2013

Yes, same here. It might be mindful to set up a fork / team for this and publish it ourselves.

@JayH5
Copy link

JayH5 commented Sep 1, 2013

I don't really have much invested in this project atm. I used it briefly at a company I interned at a couple of months ago. That being said, this is one of the nicer image zoom implementations I've found and with a few fixes I think it could be really great. If you want to organise a fork/team to carry on development then I'd be willing to help out where I can but it would only be in a limited way.

It depends really on what you have in mind. Beyond this pull request I'd also like to see the two I've made (#63, #64) get merged. Would be even better if somebody implements EdgeEffectCompat at some point for an overscroll effect.

Would be good if we could get some feedback from @chrisbanes

@saimr
Copy link

saimr commented Sep 10, 2013

I tried this it might work for you guys. No errors so far.
In PhotoviewAttacher File replace clean up function with the function below

@SuppressLint("NewApi")
    @SuppressWarnings("deprecation")
    public final void cleanup() {
        if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN)
        {
            if (null != mImageView) {
                mImageView.get().getViewTreeObserver().removeOnGlobalLayoutListener(this);
                }

                    if (null != mViewTreeObserver && mViewTreeObserver.isAlive()) {
                         mViewTreeObserver.removeOnGlobalLayoutListener(this);

                    mViewTreeObserver = null;

                    // Clear listeners too
                    mMatrixChangeListener = null;
                    mPhotoTapListener = null;
                    mViewTapListener = null;
                    // Finally, clear ImageView
                    mImageView = null;
                    }

        }
        else
        {
        if (null != mImageView) {
            mImageView.get().getViewTreeObserver().removeGlobalOnLayoutListener(this);
            }

                if (null != mViewTreeObserver && mViewTreeObserver.isAlive()) {
                     mViewTreeObserver.removeGlobalOnLayoutListener(this);

                mViewTreeObserver = null;

                // Clear listeners too
                mMatrixChangeListener = null;
                mPhotoTapListener = null;
                mViewTapListener = null;
                // Finally, clear ImageView
                mImageView = null;
                }
        }
            }

@andriytam
Copy link

It appears that mViewTreeObserver.isAlive() is false on JellyBean while mImageView.get().getViewTreeObserver().isAlive() is true. I have fixed this issue by removing mViewTreeObserver field and getting ViewTreeObserver from ImageView once it is required.

@smarek
Copy link
Contributor

smarek commented Sep 21, 2013

@andriytam can you create pull request against current dev branch please?

@shawwinbin
Copy link

@saimr thank you .it work for me.

@simonbengtsson
Copy link

Updating to the recently released 1.2.2 fixed that bug. I haven't seen the error since I updated at least.

@zhangxincheng
Copy link

@saimr thank you .it work for me.

@kingideayou
Copy link

thanks.

@mybslj
Copy link

mybslj commented Jan 4, 2015

@saimr It's still oocurring!

@arlindiDev
Copy link

There is no mViewTreeObserver field?

@Silence2016
Copy link

i have replace the cleanup function but there is no mViewTreeObserver field,where does it is decareed

@UshioYu
Copy link

UshioYu commented Jun 1, 2016

Where is mViewTreeObserver?????I can't find it.Could anyone can help me??

@aerb
Copy link

aerb commented Jan 6, 2017

Think I'm seeing a similar issue on 1.2.4, PhotoView spams my log with:
PhotoViewAttacher: ImageView no longer exists. You should not use this PhotoViewAttacher any more., even though I've called cleanup.

I also found that it was not correctly removing itself form the ViewTreeObserver. For future reference to anyone with the problem the quick-and-dirty fix was:

attacher.cleanup();
getViewTreeObserver().removeOnGlobalLayoutListener(attacher);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests