Android Studio E/dalvikvm:找不到类'.DatabaseHelper',从方法.DatabaseManager引用 [英] Android Studio E/dalvikvm﹕ Could not find class '.DatabaseHelper', referenced from method .DatabaseManager
问题描述
您好,我在运行时使用 Android Studio 时遇到此错误,但仅限于 SDK 版本 <= 19 的设备上.一切都编译正常,但我在我的 databaseHelper 类上遇到此错误.
Hello I'm getting this error using Android Studio on runtime but only on devices with an SDK version <= 19. Everything compiles ok but I get this error on my databaseHelper Class.
java.lang.NoClassDefFoundError:
这是我的应用 build.gradle:
Here is my app 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 时一切正常这是我更新的内容:
My databaseHelper class extends OrmLiteSqliteOpenHelper
Everything was working fine while my compileSdkVersion was at 19
Here is what I updated:
- gradle:
classpath 'com.android.tools.build:gradle:1.1.0'
> 1.3.0 - sdk 版本:
compileSdkVersion 19
> 23 - appcompat:
com.android.support:appcompat-v7:19.0.1
> 23 - 游戏服务
- gradle:
classpath 'com.android.tools.build:gradle:1.1.0'
> 1.3.0 - sdk Version:
compileSdkVersion 19
> 23 - appcompat:
com.android.support:appcompat-v7:19.0.1
> 23 - play-services
我的 databaseHelper 类与其他工作正常的类在同一个包中!
My databaseHelper Class is in the same package than other Classes which work fine !
感谢您的帮助
推荐答案
因为你的 build.gradle 中有 multiDexEnabled true
.确保您的应用程序类正在扩展 MultiDexApplication
而不是 Application
类.
As you have multiDexEnabled true
in your build.gradle. Make sure your application class is extending MultiDexApplication
instead of the Application
class.
或者,按照文档中的建议,您可以将以下方法添加到您的应用程序类中.
Alternatively, as suggested in the docs, you can add the following method to your application class.
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
这篇关于Android Studio E/dalvikvm:找不到类'.DatabaseHelper',从方法.DatabaseManager引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!