gpt4 book ai didi

java - Realm Java 迁移 : Property has been made required

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:31:40 25 4
gpt4 key购买 nike

适用于大多数全新安装,但在最新的应用程序更新后出现了很多关于此问题的报告。更新之间已经有一段时间了,所以我认为这可能是由于用户在我添加模式之前从非常旧的版本更新造成的......但其他人说他们已经从全新安装中看到了这一点。 Java Realm 是 realm-gradle-plugin:5.1.1

感谢任何帮助,谢谢!

错误:

Caused by io.realm.exceptions.RealmMigrationNeededException
Migration is required due to the following errors: - Property 'Loan.loanRatePct' has been made required.
...
...onCreate (Activity.java:168)

MyMigration.java

if (oldVersion == 0) {
schema.get("Storage")
.addField("heat", String.class);
oldVersion++;
}

if (oldVersion == 1) {
schema.get("Env")
.addField("gameType", String.class);
oldVersion++;
}

if (oldVersion == 2) {
schema.get("Loan")
.addField("loanRatePct", Double.class);
schema.create("GameMode")
.addField("md", String.class)
.addField("name", String.class)
.addField("days", int.class)
.addField("term", int.class)
.addField("rate", String.class)
.addField("amount", int.class)
.addField("icon", int.class);
schema.create("Leaderboard")
.addField("score", String.class);

oldVersion++;
}

if (oldVersion == 3) {
schema.get("Leaderboard")
.addField("mode", String.class);
oldVersion++;
}

MyApplication.java

Realm.init(getApplicationContext());
RealmConfiguration config = new RealmConfiguration.Builder()
//todo: EVERY UPDATE: is new schema needed?
.schemaVersion(4) // Must be bumped when the schema changes
.migration(new MyMigration()) // Migration to run instead of throwing an exception
.build();
Realm.setDefaultConfiguration(config);

Activity.java

protected void onCreate(Bundle savedInstanceState) {    
realm = Realm.getDefaultInstance();
...
}

编辑:忘记了:

贷款.java

public class Loan extends RealmObject {
String theloan;
int loan;
int loanRate;
double loanRatePct;
int loanBalance;
}

最佳答案

Double 表示 nullable double

double 表示 non-null double

所以 .addField("loanRatePct", Double.class); 应该是 .addField("loanRatePct", double.class);

关于java - Realm Java 迁移 : Property has been made required,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50808395/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com