对象不是此Realm的架构的一部分

Riy*_*sen 14 java android realm

一旦我尝试从Realm数据库中获取对象,应用程序崩溃了,我收到此错误:

java.lang.RuntimeException: Unable to start activity 
      ComponentInfo{com.repdev.realtimedelijn/com.repdev.realtimedelijn.activity.MainActivity}: 
    java.lang.IllegalArgumentException: Haltes is not part of the schema for this Realm
Run Code Online (Sandbox Code Playgroud)

这是我的活动它发生了

   @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Fabric.with(this, new Crashlytics());
    setContentView(R.layout.activity_main);
    Context context = this;
    View view = this.getWindow().getDecorView();

    realm = Realm.getInstance(getRealmConfiguration());
    RealmResults<Haltes> haltes = realm
            .where(Haltes.class)
            .findAll();
    HaltesRecyclerViewAdapter haltesRecyclerViewAdapter =
            new HaltesRecyclerViewAdapter(this, haltes, true, true);
    RealmRecyclerView realmRecyclerView =
            (RealmRecyclerView) findViewById(R.id.realm_recycler_view);
    realmRecyclerView.setAdapter(haltesRecyclerViewAdapter);
}
Run Code Online (Sandbox Code Playgroud)

这是模型

有人知道如何解决它?公共类Haltes实现RealmModel {

@PrimaryKey
private long id;

private String halteNaam;
private String halteNummer;

public long getId() {

    return id;
}

public void setId(long id) {

    this.id = id;
}

public String getHalteNaam() {

    return halteNaam;
}

public void setHalteNaam(String halteNaam) {

    this.halteNaam = halteNaam;
}

public  String getHalteNummer() {

    return halteNummer;
}

public void setHalteNummer(String halteNummer) {

    this.halteNummer = halteNummer;
}
Run Code Online (Sandbox Code Playgroud)

}

小智 11

retrolambdaandroid-apt一起使用它时遇到了同样的问题. 更改 app级build.gradle文件中插件的顺序对我有用:

apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'me.tatarka.retrolambda'
apply plugin: 'realm-android'
Run Code Online (Sandbox Code Playgroud)

Github问题:https://github.com/realm/realm-java/issues/3783#issuecomment-260578984


har*_*h_v 9

通过apply plugin: 'realm-android'在所有其他插件之后声明来解决我的问题.

应用级Gradle

apply plugin: 'android-apt'
apply plugin: 'realm-android'

android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    buildToolsVersion rootProject.ext.buildToolsVersion
Run Code Online (Sandbox Code Playgroud)


Eug*_*noy 6

就我而言,我需要将 kotlin-kapt 粘贴到 app.gradle

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt' <<<<<<<<<<the 1st row<<<<<<<<<
apply plugin: 'realm-android' <<<<<the second row<<<<<
Run Code Online (Sandbox Code Playgroud)

我花了6个小时来解决这个问题。现在它起作用了。上面是怎么写的——realm-android 应该添加到所有插件的末尾!