io.realm.exceptions.RealmException:找不到生成的ValidationList类

时间:2014-10-08 10:11:34

标签: android realm

 FATAL EXCEPTION: main
    Process: appwise.be.gsontestproject, PID: 17697
    java.lang.RuntimeException: Unable to start activity ComponentInfo{appwise.be.gsontestproject/appwise.be.gsontestproject.MainActivity}: io.realm.exceptions.RealmException: Could not find the generated ValidationList class
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2216)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2265)
            at android.app.ActivityThread.access$800(ActivityThread.java:145)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1206)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5140)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:611)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: io.realm.exceptions.RealmException: Could not find the generated ValidationList class
            at io.realm.Realm.createAndValidate(Realm.java:203)
            at io.realm.Realm.create(Realm.java:181)
            at io.realm.Realm.getInstance(Realm.java:159)
            at io.realm.Realm.getInstance(Realm.java:128)
            at appwise.be.gsontestproject.MainActivity.onCreate(MainActivity.java:139)
            at android.app.Activity.performCreate(Activity.java:5231)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2170)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2265)
            at android.app.ActivityThread.access$800(ActivityThread.java:145)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1206)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5140)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:611)
            at dalvik.system.NativeStart.main(Native Method)

Realm文件夹到位,libs文件夹中的注释处理器

Settings.gradle

include ':app', ':realm'

的build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.12.2'
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

app build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 20
    buildToolsVersion "20.0.0"

    defaultConfig {
        applicationId "appwise.be.gsontestproject"
        minSdkVersion 11
        targetSdkVersion 20
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    //compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:20.0.0'
    //gson
    compile 'com.google.code.gson:gson:2.3'
    //realm
    apply plugin: 'com.neenbedankt.android-apt'
    compile project(':realm')

    compile fileTree(dir: 'libs', include: ['*.jar'], exclude: ['realm-annotations-processor*.jar'])
    apt fileTree(dir: 'libs', include: ['realm-annotations-processor*.jar'])
}

我试图将它与GSON结合使用。 这看起来像一个很棒的数据库工具(我最近简要地测试了它), 但是在这个项目中,它无法工作。

答案在这里: Getting io.realm.exceptions.RealmException: Could not find the generated ValidationList class when trying to get a Realm object

无法帮助我。

1 个答案:

答案 0 :(得分:3)

你有

apply plugin: 'com.neenbedankt.android-apt'

在你的依赖关系定义中,这可能是我怀疑会触发注释处理器的原因。它应该在外面。

另外,Realm 0.71刚刚在JCenter上作为一个jar发布,所以理想情况下你应该只有

compile 'io.realm:realm-android:0.71.0

在您的依赖项中,而不是您现在使用apt。 您可以在此处查看更多内容:http://realm.io/docs/java/0.71.0/

简而言之,您的依赖项部分应如下所示:

dependencies {
    compile 'com.android.support:appcompat-v7:20.0.0'
    compile 'com.google.code.gson:gson:2.3'
    compile 'io.realm:realm-android:0.71.0'
}