解决PhotoView的报错信息:ImageView no longer exists. You should not use this PhotoViewAttacher any more.
来源:互联网 发布:高级程序员php面试 编辑:程序博客网 时间:2024/05/16 02:28
PhotoView是一个易于使用的带缩放ImageView功能的第三方开源框架。项目地址(链接)
最近接收公司的多媒体项目,处理图片这个模块的时候,发现经常弹出以下异常信息:
ImageView no longer exists. You should not use this PhotoViewAttacher any more.
google了一下,发现第一页的搜索结果,给出的解决办法(链接)都是如下:
在PhotoViewAttacher 文件中 更改cleanup方法
// @SuppressWarnings("deprecation")// public final void cleanup() {// if (null != mImageView) {// mImageView.get().getViewTreeObserver().removeGlobalOnLayoutListener(this);// }// mViewTreeObserver = null;//// // Clear listeners too// mMatrixChangeListener = null;// mPhotoTapListener = null;// mViewTapListener = null;//// // Finally, clear ImageView// mImageView = null;// }@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; } }}
实践之后,发现问题依旧,遂此种方法是不可行的,自己只能在github源项目上看看有没有遇到相同问题的人,果不其然,还真给我找到了。
针对此问题,该开源项目的作者chrisbanes的原话(链接)是:
Change getImageView() to log an error rather than throw an exception.
大意更改getImageView()以log方式记录错误,而不是抛出异常。那么:
public final ImageView getImageView() { ImageView imageView = null; if (null != mImageView) { imageView = mImageView.get(); } // If we don't have an ImageView, call cleanup() if (null == imageView) { cleanup(); // throw new IllegalStateException(//此处经常抛异常,网上的解释是可能由于mImageView为弱引用的关系,对此,该开源框架PhotoView的创建人chrisbanes的建议是:Change getImageView() to log an error rather than throw an exception. // "ImageView no longer exists. You should not use this PhotoViewAttacher any more."); try { throw new IllegalStateException( "ImageView no longer exists. You should not use this PhotoViewAttacher any more."); } catch (Exception e) { Log.w("PhotoViewAttacher", "[IllegalStateException] e = "+e.toString()); } } return imageView;}
按此方法更改后,再无此异常出现,欢迎大家指正
1 0
- 解决PhotoView的报错信息:ImageView no longer exists. You should not use this PhotoViewAttacher any more.
- ImageView no longer exists. You should not use this PhotoViewAttacher any more
- 使用 PhotoView 出现: ImageView no longer exists.
- PhotoView问题 ImageView no longer exists
- PhotoView问题 ImageView no longer exists.
- PhotoView问题 ImageView no longer exists.
- 提交app报错you are not authorized to use this service的解决办法
- Cython报错解决: #error Do not use this file, ...
- Git fetch和git pull的区别, 解决Git报错:error: You have not concluded your merge (MERGE_HEAD exists).
- Git fetch和git pull的区别, 解决Git报错:error: You have not concluded your merge (MERGE_HEAD exists).
- 解决Git报错:error: You have not concluded your merge (MERGE_HEAD exists).
- 【完美解决系列】This support library should not use a different version
- 关于react-router中<Link>的调试: You should not use <Link> outside a <Router>
- 使用AlertDialog报错 You need to use a Theme.AppCompat theme (or descendant) with this activity.之解决
- 使用AlertDialog报错 You need to use a Theme.AppCompat theme (or descendant) with this activity.之解决
- Could not find any matches for com.android.support:appcompat-v7:23.+报错的解决
- This support library should not use a different version
- QWidget::paintEngines:should no longer be called.
- ScrollView嵌套ListView的解决方案
- 软件交互原型工具
- [Leetcode] Construct Binary Tree from Inorder and Postorder Traversal
- IDC,Internet Data Center
- Lua string 字符串
- 解决PhotoView的报错信息:ImageView no longer exists. You should not use this PhotoViewAttacher any more.
- WPF C#仿ios 安卓 红点消息提示
- IDEA中创建多级package的问题
- 【GOLANG】Go语言学习-select用法
- 简述DNS进行域名解析的原理
- Android开发-01 九宫解锁实现
- Kaggle入门
- Nginx配置文件(nginx.conf)配置详解(二)
- 在MyEclipse导入项目后,js文件报错