android - java.lang.NoClassDefFoundError : Could not initialize class android. View .GestureDetector

标签 android eclipse

我在尝试初始化水平 ScrollView 类时遇到此错误:

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 是私有(private) GestureDetector:

private GestureDetector mGesture;

my UI

最佳答案

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

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是否为null。

关于android - java.lang.NoClassDefFoundError : Could not initialize class android. View .GestureDetector,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16856497/

相关文章:

android - 广播接收器在 Android 6.0 Marshmallow 中不起作用

java - 从 JNI 代码中阻止对话框

java - Mac OS 10.7 Lion 下 Eclipse 中断

eclipse - 使用谷歌应用引擎时,更改不会反射(reflect)在本地主机中

c++ - 为 CDT 项目将多个库添加到 Eclipse-IDE

android - 无法启动 Activity ComponentInfo{com.viraandroid.test/com.paypal.android.sdk.payments.PaymentActivity} :

android - 使用 Koin 中的 inject() 函数类型不匹配

java - Google 在 Appcompactivity 中的 AutoCompleteTextView 上放置 api 调用 - Android

java - 在 Android 上创 build 置向导

Android 风格应用 minSdkVersion ="8"targetSdkVersion ="21"