As soon as I try to get my object from Realm database, the app crashed and I get this error:
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
This is my Activity were it happens
@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);
}
and here is the model
Someone an idea how to fix it? public class Haltes implements 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;
}
}
My problem was solved by declaring apply plugin: 'realm-android'
after all other plugins.
App level Gradle
apply plugin: 'android-apt'
apply plugin: 'realm-android'
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
had the same problem while using it along side with retrolambda and android-apt.
changing the order of plugins in app level build.gradle
file worked for me :
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'me.tatarka.retrolambda'
apply plugin: 'realm-android'
Github issue : https://github.com/realm/realm-java/issues/3783#issuecomment-260578984
In my case I was need to paste kotlin-kapt to 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<<<<<
I spent 6 hours to solve this problem. And now it works. And how was written above - realm-android should be added to the end of all plugins!
Are you using the @RealmClass
annotation?
If you are using annotations, make sure you have annotation processing enabled in your Android studio settings.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With