ImageView no longer exists. You should not use this PhotoViewAttacher any more.
The full error is:
写道
java.lang.IllegalStateException: ImageView no longer exists. You should not use this PhotoViewAttacher any more.
uk.co.senab.photoview.PhotoViewAttacher.getImageView(PhotoViewAttacher.java:209)
uk.co.senab.photoview.PhotoViewAttacher.onSingleTapConfirmed(PhotoViewAttacher.java:351)
android.view.GestureDetector$GestureHandler.handleMessage(GestureDetector.java:320)
uk.co.senab.photoview.PhotoViewAttacher.getImageView(PhotoViewAttacher.java:209)
uk.co.senab.photoview.PhotoViewAttacher.onSingleTapConfirmed(PhotoViewAttacher.java:351)
android.view.GestureDetector$GestureHandler.handleMessage(GestureDetector.java:320)
在PhotoViewAttacher 文件中 更改cleanup方法
参考
https://github.com/chrisbanes/PhotoView/issues/67
定位到找到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;
// }
// 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;
}
}
}
@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;
}
}
}
相关推荐
java.lang.IllegalStateException: Failed to load ApplicationContext at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate....
Java 中 ThreadPoolExecutor 常识汇总 ThreadPoolExecutor 是 Java 中的一种线程池实现,用于管理线程池中的线程,提高系统的并发处理能力。在 Java 中,线程池技术广泛应用于并发编程中,通过调用 ...
如果没有这么做,会触发一个 IllegalState异常。 在 onMeasure() 方法中,还需要调用孩子的 measure() 方法,来测量出 view 的大小。父 view 使用 width 参数和 height 参数来提供约束信息。实际上,view 的测量...
Java 容器类源码详解 Deque 与 ArrayDeque Java 容器类源码详解 Deque 与 ArrayDeque 主要介绍了 Java 容器类源码详解 Deque 与 ArrayDeque,Deque 接口继承自 Queue 接口,但 Deque 支持同时从两端添加或移除元素...