我们的SDK使用领域,我们生成一个aar文件,当应用程序使用此aar时,扩展RealmObject的对象将 案例NullPointerException。例如schema.get(“ ResSingleGroupModel”)
项目:
classpath“ io.realm:realm-gradle-plugin:3.1.3”
应用gradle
应用插件:“ realm-android”
库gradle
应用插件:“ realm-android”
java.lang.NullPointerException: Attempt to invoke virtual method 'java.util.Set io.realm.RealmObjectSchema.getFieldNames()' on a null object reference
at com.ideal.chatsdk.db.IMRealmMigration.addResSingleGroupModel(IMRealmMigration.java:219)
at com.ideal.chatsdk.db.IMRealmMigration.migrate(IMRealmMigration.java:175)
IMRealmMigration:
private void addResSingleGroupModel(RealmSchema schema) {
RealmObjectSchema groupModelSchema = schema.get("ResSingleGroupModel");
Set<String> groupModelSet = groupModelSchema.getFieldNames();
if (!groupModelSet.contains("creator")) {
//新增@Required的id
groupModelSchema.addField("creator", String.class);
}
}
非常感谢您的帮助。