Android Studio E/dalvikvm:找不到类 '.DatabaseHelper',从方法 .DatabaseManager 引用

标签 android android-studio ormlite

您好,我在运行时使用 Android Studio 时遇到此错误,但仅限于 SDK 版本 <= 19 的设备。一切编译正常,但我在 databaseHelper 类上遇到此错误。

java.lang.NoClassDefFoundError:

这是我的应用程序 build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion '23.0.1'
    useLibrary  'org.apache.http.legacy'

    defaultConfig {
        minSdkVersion 11
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled true
        }
    }
}



dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.google.android.gms:play-services:7.8.0'
    compile 'com.android.support:appcompat-v7:23.0.1'
    compile 'com.github.johnpersano:supertoasts:1.3.4@aar'
    compile 'com.readystatesoftware.systembartint:systembartint:1.0.3'
    compile 'com.navercorp.pulltorefresh:library:3.2.0@aar'
    compile 'com.parse.bolts:bolts-android:1.2.1'
    compile 'com.j256.ormlite:ormlite-android:4.48'
    compile 'com.j256.ormlite:ormlite-core:4.48'
}

我的 databaseHelper 类扩展 OrmLiteSqliteOpenHelper 当我的 compileSdkVersion 为 19 时一切正常 这是我更新的内容:

  • gradle: classpath 'com.android.tools.build:gradle:1.1.0' > 1.3.0
  • sdk版本:compileSdkVersion 19 > 23
  • 应用程序兼容性:com.android.support:appcompat-v7:19.0.1 > 23
  • 播放服务

我的 databaseHelper 类与其他工作正常的类在同一个包中!

谢谢你的帮助

最佳答案

因为您的 build.gradle 中有 multiDexEnabled true。确保您的应用程序类正在扩展 MultiDexApplication而不是 Application 类。

或者,按照文档中的建议,您可以将以下方法添加到您的应用程序类中。

@Override
protected void attachBaseContext(Context base) {
    super.attachBaseContext(base);
    MultiDex.install(this);
}

关于Android Studio E/dalvikvm:找不到类 '.DatabaseHelper',从方法 .DatabaseManager 引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32697460/

相关文章:

android - react native AppState 在 Android 上没有 'inactive' 状态

Android:查找内存泄漏的工具?

Android ormlite 多表映射

android - Android Studio 3 中的 "Activity Manager State"在哪里?

android - ORMLite 不能做 queryForId

android - 更新外部对象 ORMLite - ANDROID

java - 移除 ViewGroup 中的 View

java - Android Studio 中的 Google Maps v2。未找到 GeoPoint

flutter - 未配置 Dart SDK

Listview + Gridview 的 Android Studio 布局预览