【问题标题】:Green Dao Could not init DAOConfigGreen Dao 无法初始化 DAOConfig
【发布时间】:2015-12-15 10:39:49
【问题描述】:

我尝试使用一个旧的 android 应用程序,它使用 Green Dao 这样的数据库,这个应用程序也有味道,所以我编译并安装了 apk,但应用程序无法启动它给出了这个异常:

Process: com.xxxx.boeufaujardin, PID: 20011 java.lang.RuntimeException: Unable to create application com.android.tools.fd.runtime.BootstrapApplication: de.greenrobot.dao.DaoException: Could not init DAOConfig
                                                   at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4556)
                                                   at android.app.ActivityThread.access$1500(ActivityThread.java:151)
                                                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
                                                   at android.os.Handler.dispatchMessage(Handler.java:102)
                                                   at android.os.Looper.loop(Looper.java:135)
                                                   at android.app.ActivityThread.main(ActivityThread.java:5254)
                                                   at java.lang.reflect.Method.invoke(Native Method)
                                                   at java.lang.reflect.Method.invoke(Method.java:372)
                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
                                                Caused by: de.greenrobot.dao.DaoException: Could not init DAOConfig
                                                   at de.greenrobot.dao.DaoConfig.<init>(DaoConfig.java:88)

其他原因:

Caused by: java.lang.NullPointerException: Attempt to read from field 'int de.greenrobot.dao.Property.ordinal' on a null object reference
                                                       at de.greenrobot.dao.DaoConfig.reflectProperties(DaoConfig.java:99)
                                                       at de.greenrobot.dao.DaoConfig.<init>(DaoConfig.java:51)
                                                       at de.greenrobot.dao.AbstractDaoMaster.registerDaoClass(AbstractDaoMaster.java:43) 

这是我的毕业典礼:

apply plugin: 'com.android.application'

buildscript {
    repositories {
        mavenCentral()
        maven { url 'http://download.crashlytics.com/maven' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.0.0-alpha1'
        classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.+'
    } } apply plugin: 'android' apply plugin: 'crashlytics' repositories {
    mavenCentral()
    maven { url 'http://download.crashlytics.com/maven' } }


android {
    compileSdkVersion 19
    buildToolsVersion '19.1.0'

    //useOldManifestMerger false

    dexOptions {
        preDexLibraries = false
    }

    packagingOptions {
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }

    signingConfigs {
        debug_config {

        }
        release_config {

        }
    }
    compileSdkVersion 19
    buildToolsVersion '19.1.0'
    defaultConfig {
        applicationId 'com.xxxxx.xx'
        minSdkVersion 11
        targetSdkVersion 19
        versionCode 11
        versionName '0.3'
        signingConfig signingConfigs.debug_config
        // Enabling multidex support.
      //  multiDexEnabled true
    }
    buildTypes {
        release {
            debuggable false
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {

            debuggable true
            signingConfig signingConfigs.debug_config
            //renderscriptDebugBuild false
        }
    }
    productFlavors {
        Menu {
            applicationId "com.paperpad.menu"
            manifestPlaceholders = [activityLabel : "Menu", gcmPackage : "com.paperpad.menu"]
            minSdkVersion 11
            signingConfig signingConfigs.debug_config
            targetSdkVersion 19
            versionCode 11
            versionName '0.3'

            ext.enableCrashlytics = false
        }
        ServiceApps {
            ext.enableCrashlytics = false // true
            applicationId "xxxx.xxxxx.boeufaujardin"
            minSdkVersion 11
            signingConfig signingConfigs.debug_config
            targetSdkVersion 19
            versionCode 19
            versionName '0.5.4'

        }
    }

    sourceSets { //        main { //            manifest.srcFile 'AndroidManifest.xml' //            java.srcDirs = ['java'] //         resources.srcDirs = ['res'] //            aidl.srcDirs = ['src'] //    renderscript.srcDirs = ['src'] //            res.srcDirs = ['res'] //  assets.srcDirs = ['assets'] //        }


        ServiceApps {
            manifest.srcFile 'ServiceApps/AndroidManifest.xml'
            resources.srcDirs = ['ServiceApps/res']
            res.srcDirs = ['ServiceApps/res']
        }
    } }

dependencies {
    compile('com.android.support:appcompat-v7:19.1.0') {
        // really use 19.1.0 even if something else resolves higher
        //force = true
       exclude module: 'support-v4'}

   // compile 'com.android.support:multidex:1.0.1'
    //compile 'com.crashlytics.android:crashlytics:1.+'
    compile project(':headerListView')
    compile files('libs/freemarker.jar')
    compile files('libs/httpmime-4.1.jar')
    compile files('libs/crashlytics.jar')
    compile files('libs/simple-xml-2.6.9.jar')
    compile files('libs/json-simple-1.1.1.jar')
    compile files('libs/greenDAO.jar')
    compile files('libs/gcm-src.jar')
    compile files('libs/gcm.jar')
    compile files('libs/greenDAO-generator.jar')
    compile files('libs/disklrucache-1.3.1.jar')
    compile files('libs/httpclient-4.2.3.jar')
    compile files('libs/trace.jar')
    compile files('libs/jackson-databind-2.1.4.jar')
    compile files('libs/jackson-core-2.1.4.jar')
    compile files('libs/jackson-annotations-2.1.4.jar')
    compile files('libs/universal-image-loader-1.8.4.jar')
    compile files('libs/universal-image-loader-1.8.4-sources.jar')
    compile files('libs/picasso-2.2.0.jar')
    compile project(':library')
    compile files('libs/Android-BitmapCache-2.1.jar')
    //compile 'org.jraf:android-switch-backport:1.3.1'
    compile files('libs/android-support-v13.jar') }

【问题讨论】:

  • 您找到问题的根本原因了吗?有解决方案吗?如果是,请发布。
  • 对不起我的朋友,我把它传给了Realm,它是一个比GreenDao 更完美的数据库,我建议你使用它!祝你有美好的一天。
  • 你能提供一个试用领域的链接吗?就像一个用于 CRUD 操作的 sn-p
  • 试试这个链接 www.realm.io
  • 朋友,你用的是MAC还是windows?我需要适用于 windows 的领域浏览器,不幸的是 windows 领域不支持浏览器,如果你使用的是 windows,那么告诉我如何处理浏览部分?

标签: java android greendao


【解决方案1】:

我在下面添加了proguard-rules。

-keep class xxx.dao.**{*;}

(xxx 是我放置 DAO 类文件的包名。)

它对我有用。

【讨论】:

  • 谢谢!对我来说它不需要 .dao。
【解决方案2】:

----- 像这样声明属性------

public class FolderDao extends AbstractDao<Folder, Long> {
public static final String TABLENAME = "FOLDER";
private DaoSession daoSession;

public static class Properties {
    public static final Property FolderPath = new Property(8, String.class, "folderPath", false, "FOLDER_PATH");
    public static final Property FolderSourceId = new Property(5, Long.class, "folderSourceId", false, "FOLDER_SOURCE_ID");
    public static final Property Id = new Property(0, Long.class, "id", true, "_id");
    public static final Property IsCamera = new Property(3, Boolean.class, "isCamera", false, "IS_CAMERA");
    public static final Property IsHidden = new Property(7, Boolean.class, "isHidden", false, "IS_HIDDEN");
    public static final Property IsUserCreated = new Property(6, Boolean.class, "isUserCreated", false, "IS_USER_CREATED");
    public static final Property Name = new Property(1, String.class, "name", false, "NAME");
    public static final Property Source = new Property(4, Integer.class, "source", false, "SOURCE");
    public static final Property UserType = new Property(2, String.class, "userType", false, "USER_TYPE");
}

public FolderDao(DaoConfig daoConfig) {
    super(daoConfig);
}

public FolderDao(DaoConfig daoConfig, DaoSession daoSession) {
    super(daoConfig, daoSession);
    this.daoSession = daoSession;
}

如果你不写 public 所以会出现类似 Caused by: de.greenrobot.dao.DaoException: Could not init DAOConfig 的错误 或静态的原因:java.lang.NullPointerException:尝试从空对象引用上的字段“int de.greenrobot.dao.Property.ordinal”读取

【讨论】:

    猜你喜欢
    • 2021-12-17
    • 2017-06-20
    • 1970-01-01
    • 1970-01-01
    • 2017-08-02
    • 1970-01-01
    • 1970-01-01
    • 2022-01-15
    • 2020-01-22
    相关资源
    最近更新 更多