本文介绍了java.lang.NoClassDefFoundError的:无法初始化类android.view.GestureDetector的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想初始化一个水平滚动视图类时收到此错误:
I am getting this error when trying to initialize a horizontal scroll view class:
java.lang.NoClassDefFoundError: Could not initialize class android.view.GestureDetector
private synchronized void initView() {
mLeftViewIndex = -1;
mRightViewIndex = 0;
mDisplayOffset = 0;
mCurrentX = 0;
mNextX = 0;
mMaxX = Integer.MAX_VALUE;
mScroller = new Scroller(getContext());
mGesture = new GestureDetector(getContext(), mOnGesture);
}
错误被追溯到这一行:
the error is being traced back to this line:
mGesture = new GestureDetector(getContext(), mOnGesture);
mGesture是一家民营GestureDetector:
mGesture is a private GestureDetector:
private GestureDetector mGesture;
推荐答案
您不作为尖端说需要它时,在编辑模式下,无论如何,这样做的:
You don't need it when in edit mode anyway, so do as the tip says:
private synchronized void initView() {
mLeftViewIndex = -1;
mRightViewIndex = 0;
mDisplayOffset = 0;
mCurrentX = 0;
mNextX = 0;
mMaxX = Integer.MAX_VALUE;
if (!this.isInEditMode()) {
mScroller = new Scroller(getContext());
mGesture = new GestureDetector(getContext(), mOnGesture);
}
}
然后检查mGesture和mCcroller是在code空使用前。
And then check for mGesture and mCcroller being null in the code before using.
这篇关于java.lang.NoClassDefFoundError的:无法初始化类android.view.GestureDetector的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!