java 对象不是该领域架构的一部分
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37887303/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Object is not part of the schema for this Realm
提问by Riyan Fransen
As soon as I try to get my object from Realm database, the app crashed and I get this error:
一旦我尝试从 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
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 {
有人知道如何解决它吗?公共类 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;
}
}
}
采纳答案by harsh_v
My problem was solved by declaring apply plugin: 'realm-android'
after all other plugins.
我的问题是通过apply plugin: 'realm-android'
在所有其他插件之后声明来解决的。
App level Gradle
应用级 Gradle
apply plugin: 'android-apt'
apply plugin: 'realm-android'
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
回答by Mohammad Mirrajabi
had the same problem while using it along side with retrolambdaand android-apt.
changing the order of pluginsin app level build.gradle
file worked for me :
在与retrolambda和android-apt一起使用时遇到了同样的问题。
更改应用程序级build.gradle
文件中插件的顺序对我有用:
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
Github 问题:https: //github.com/realm/realm-java/issues/3783#issuecomment-260578984
回答by Eugene Voronoy
In my case I was need to paste kotlin-kapt to app.gradle
就我而言,我需要将 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<<<<<
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!
我花了6个小时来解决这个问题。现在它起作用了。上面是怎么写的——应该将realm-android添加到所有插件的末尾!
回答by Cuong Nguyen
Try this: Android Studio -> Build -> Rebuild & Clean Project
试试这个:Android Studio -> Build -> Rebuild & Clean Project
回答by Bob
Are you using the @RealmClass
annotation?
If you are using annotations, make sure you have annotation processing enabled in your Android studio settings.
你在使用@RealmClass
注解吗?如果您正在使用注释,请确保您在 Android Studio 设置中启用了注释处理。
回答by Mina Samy
I believe this has to do with adding a new Realm Model class after some models were already added. try un installing the application and run again or migrate your schema.
我相信这与在添加了一些模型之后添加一个新的 Realm Model 类有关。尝试卸载应用程序并再次运行或迁移您的架构。
Does your Haltes class extends RealmObject?
您的 Haltes 类是否扩展了 RealmObject?
Make it like this:
让它像这样:
public class Haltes extends RealmObject
or
或者
@RealmClass
public class Haltes implements RealmModel
回答by Christian Melchior
You haven't added Realm to your build.gradle
file: https://bitbucket.org/repdev/realtimedelijnandroid/src/77c531768dc1250b4d5b5c6c7fd4e6100764177d/build.gradle?at=master&fileviewer=file-view-default
您尚未将 Realm 添加到您的build.gradle
文件中:https: //bitbucket.org/repdev/realtimedelijnandroid/src/77c531768dc1250b4d5b5c6c7fd4e6100764177d/build.gradle?at=master&fileviewer=file- view-default
See how here: https://realm.io/docs/java/latest/#installation
在这里查看方法:https: //realm.io/docs/java/latest/#installation
Your top level build.gradle
file should have this
你的顶级build.gradle
文件应该有这个
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "io.realm:realm-gradle-plugin:1.0.1"
}
}
Your app level build.gradle
file should have this at the top:
您的应用程序级别build.gradle
文件应该在顶部包含以下内容:
apply plugin: 'realm-android'
回答by Nidhin
I got this exception when using a library project with my app project and realm plugin is only applied to the library project. When I added realm plugin `apply plugin: 'realm-android' to the app project ,the exception gone.
将库项目与我的应用程序项目一起使用时出现此异常,并且领域插件仅应用于库项目。当我将领域插件`apply plugin: 'realm-android' 添加到应用程序项目时,异常消失了。
Make sure realm plugin added to every gradle project that uses realm.
确保将领域插件添加到每个使用领域的 gradle 项目中。
回答by Fadils
For those of you who use a mixture of Kotlin in your codebase, then this problem will be solved by applying kotlin-kapt
before realm-android
.
对于那些在代码库中混合使用 Kotlin 的人,这个问题将通过应用kotlin-kapt
before来解决realm-android
。
That is:
那是:
apply plugin: 'kotlin-kapt'
apply plugin: 'realm-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'realm-android'