Green Dao无法初始化DAOConfig

时间:2015-12-15 10:39:50

标签: java android greendao

我尝试使用一个旧的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') }

2 个答案:

答案 0 :(得分:0)

------属性声明如下------

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

如果你不写公共所以发生错误如引起:de.greenrobot.dao.DaoException:无法初始化DAOConfig 或者静态而不是引起:java.lang.NullPointerException:尝试从空对象引用上的字段'int de.greenrobot.dao.Property.ordinal'中读取

答案 1 :(得分:0)

我在下面添加了保护规则。

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

(xxx是放置DAO类文件的packageName。)

对我有用。