Java.lang.IllegalArgumentException: Category is not part of the schema for this Realm
I am using Android Studio 1.2.2 and Realm 0.81.1. I created a Category model as follows:
@RealmClass
public class Category extends RealmObject {
private String name;
// getter and setter
}
But I am getting java.lang.IllegalArgumentException: Category is not part of the schema for this Realm
I even turned on annotation processing, but the error still persists.
How can I resolve this error? Any help is greatly appreciated.
Update
I delved into the Kingdom code. I found that in the Util.class file
if(!superclass.equals(RealmObject.class)) {
clazz = superclass;
}
This is a superclass check of the model I am using. When I printed out the superclass of the mode; yourself, for example:
category.getClass().getSuperclass().getName();
I am getting 'io.realm.RealmObject' which is not equal to RealmObject.class. Therefore, Realm may not treat it as a RealmObject.
Could this be the cause causing the error?
source to share
I found that the order in which the plugins are listed in your app's build.gradle file does matter. In my case, I had the apply: "realm-android" plugin, but apparently it was specified too early. Putting it on the last job.
It failed.
apply plugin: 'com.android.application'
apply plugin: 'realm-android'
apply plugin: 'android-apt'
apply plugin: 'com.neenbedankt.android-apt'
It worked nonetheless (note how big the real android is).
apply plugin: 'com.android.application'
apply plugin: 'android-apt'
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'realm-android'
source to share
In my case, I had two one-to-many relationships. The two relationship classes were in different modules. This caused an error. When I put them in one module it worked. This is the related part from the source:
public <E extends RealmModel> E copyOrUpdate(Realm realm, E obj, boolean update, Map<RealmModel, RealmObjectProxy> cache) {
// This cast is correct because obj is either
// generated by RealmProxy or the original type extending directly from RealmObject
@SuppressWarnings("unchecked") Class<E> clazz = (Class<E>) ((obj instanceof RealmObjectProxy) ? obj.getClass().getSuperclass() : obj.getClass());
if (clazz.equals(Buddy.class)) {
return clazz.cast(BuddyRealmProxy.copyOrUpdate(realm, (Buddy) obj, update, cache));
} else {
throw getMissingProxyClassException(clazz);
}
}
source to share