java.lang.NoClassDefFoundError:无法初始化类android.view.GestureDetector

时间:2013-05-31 11:42:43

标签: android eclipse

尝试初始化水平滚动视图类时出现此错误:

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);
    }

错误正在追溯到这一行:

mGesture = new GestureDetector(getContext(), mOnGesture);

mGesture是一个私人的GestureDetector:

private GestureDetector mGesture;

my UI

1 个答案:

答案 0 :(得分:1)

无论如何,在编辑模式下你都不需要它,所以请按照提示说:

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在代码中为空。