Reputation: 245
I using Android Studio 1.2.2 and Realm 0.81.1. I have created a Model 'Category' 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 enabled Annotation Processing, but the error is still persisting.
How can I solve this error? Any help is much appreciated.
Update
I dug deeper into the Realm code. I found that in Util.class file,
if(!superclass.equals(RealmObject.class)) {
clazz = superclass;
}
It is checking the superclass of the model I am using. When I printed out the super class of the mode; myself, like:
category.getClass().getSuperclass().getName();
I am getting 'io.realm.RealmObject' which is not equal to RealmObject.class. So Realm might not be considering it as a RealmObject.
Could this be the reason that is causing error?
Upvotes: 3
Views: 3664
Reputation: 169
I found that the order in which the plugins are specified in the build.gradle file of your app matters. In my case, I had the apply plugin: 'realm-android' in it but apparently it was specified too early. Putting it last worked.
This failed.
apply plugin: 'com.android.application'
apply plugin: 'realm-android'
apply plugin: 'android-apt'
apply plugin: 'com.neenbedankt.android-apt'
Yet this worked (note how real-android is last).
apply plugin: 'com.android.application'
apply plugin: 'android-apt'
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'realm-android'
Upvotes: 2
Reputation: 881
In my case I had two One-to-Many relationship. Two classes of the relationship were in different modules. This caused error. When I put them in the same 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);
}
}
Upvotes: 0
Reputation: 103
In my case, I need to add realm plugin (apply plugin: 'realm-android') to every .gradle project that uses realm. RealRecyclerView and my main app project.
Upvotes: 4
Reputation: 1265
I don't know if you still have this issue but on my side I just clear the project and build again. Works fine after that... Please notice that I have android studio as ide.
Upvotes: 1