我正在 APP ONE 上将CSV文件转换为realm文件,然后将其作为 APP TWO 中的主数据库发送,并使用
设置为默认数据库SharedPreferences wmbPreference = PreferenceManager.getDefaultSharedPreferences(this);
boolean isFirstRun = wmbPreference.getBoolean("FIRSTRUN", true);
if (isFirstRun)
{
RealmConfiguration config = new RealmConfiguration.Builder(context)
.name(Realm.DEFAULT_REALM_NAME)
.migration(new in.webic.oralcalculations.Row())
.assetFile(context, "Default.realm")
.schemaVersion(0)
.build();
realm = realm.getInstance(config);
realm.close();
SharedPreferences.Editor editor = wmbPreference.edit();
editor.putBoolean("FIRSTRUN", false);
editor.commit();
}
我在两个应用程序中使用相同的模型类
import io.realm.DynamicRealm;
import io.realm.RealmMigration;
import io.realm.RealmObject;
import io.realm.RealmSchema;
public class Row extends RealmObject implements RealmMigration {
public Row(){}
private int id;
private int course;
private int qp1;
private int qp2;
private int col5;
private int col6;
private int col7;
public Row(int id, int course, int qp1, int qp2, int col5, int col6,int col7) {
this.id = id;
this.course = course;
this.qp1 = qp1;
this.qp2 = qp2;
this.col5 = col5;
this.col6 = col6;
this.col7 = col7;
}
public int getCol7() {
return col7;
}
public void setCol7(int col7) {
this.col7 = col7;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getCourse() {
return course;
}
public void setCourse(int course) {
this.course = course;
}
public int getQp1() {
return qp1;
}
public void setQp1(int qp1) {
this.qp1 = qp1;
}
public int getQp2() {
return qp2;
}
public void setQp2(int qp2) {
this.qp2 = qp2;
}
public int getCol5() {
return col5;
}
public void setCol5(int col5) {
this.col5 = col5;
}
public int getCol6() {
return col6;
}
public void setCol6(int col6) {
this.col6 = col6;
}
@Override
public void migrate(DynamicRealm realm, long oldVersion, long newVersion) {
RealmSchema schema = realm.getSchema();
}
}
然而我收到错误说明
java.lang.RuntimeException:无法启动活动ComponentInfo {in.webic.oralcalculations / in.webic.oralcalculations.MainActivity}:java.lang.IllegalArgumentException:Illegal Argument:Realm文件的格式无效。
我无法在格式中调试deference,因为我正在使用相同的模型类,这可能是我缺少的步骤? 任何帮助将不胜感激。