Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Realm.io can't get examples to work

I'm failing to get started with Realm.io, I've tried it in my own project aswell as with the IntroExample.

When i try to look up something, i get:

java.lang.IllegalStateException: Mutable method call during read transaction.

When i try to store something, i get:

io.realm.exceptions.RealmException: Could not find the generated proxy class

I seem to have a fundamental flaw somewhere.

apply plugin: 'com.android.application'

android {
    compileSdkVersion 19
    buildToolsVersion "20.0.0"

    defaultConfig {
        applicationId "lorem.ipsum"
        minSdkVersion 14
        targetSdkVersion 19
        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 'org.jsoup:jsoup:1.8.+'
    compile 'io.realm:realm-android:0.71.0'
}
like image 815
darken Avatar asked Dec 09 '22 06:12

darken


2 Answers

Make a @RealmClass annotation to your model class. I struggled with the same problem and went a bit deeper in the proxy class generation of Realm. Only classes with the @RealmClass annotation are generated.

@RealmClass
public class Category extends RealmObject {
    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
like image 135
Philluxx Avatar answered Dec 20 '22 14:12

Philluxx


I tried to run your example code and got a lot of exceptions regarding your model class. It looks like your getters and setters have been renamed from the default, which currently breaks the annotation processor.

I tried to change the model class to:

public class DataItem extends RealmObject {
    private String uuid;
    private String content;
    private boolean bool;

    public String getUuid() {
        return uuid;
    }

    public void setUuid(String uuid) {
        this.uuid = uuid;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public boolean isBool() {
        return bool;
    }

    public void setBool(boolean bool) {
        this.bool = bool;
    }
}

which seemed to work.

like image 35
Christian Melchior Avatar answered Dec 20 '22 13:12

Christian Melchior