我第一次使用Realm。我想将两个服务器数据与移动应用程序同步,反之亦然。 所以我设置了Realm对象服务器并尝试使用以下代码实现同步
SyncCredentials myCredentials = SyncCredentials.usernamePassword("rajesh@gmail.com", "rajesh", false);
SyncUser.loginAsync(myCredentials, BaseApplication.SERVER_URL, new SyncUser.Callback<SyncUser>() {
@Override
public void onSuccess(SyncUser result) {
Log.i(TAG, "onSuccess: "+result.getIdentity());
SyncConfiguration realmConfig = new SyncConfiguration
.Builder(SyncUser.currentUser(), BaseApplication.REALM_URL)
.name("MyDb")
.build();
Realm.getInstance(realmConfig);
}
@Override
public void onError(ObjectServerError error) {
Log.e(TAG, "onError: ", error);
Log.i(TAG, "onError: "+error.getErrorCode());
}
});
正在执行成功阻止,但同步配置会出现以下错误
java.lang.ArrayIndexOutOfBoundsException: length=0; index=-1
at io.realm.SyncConfiguration$Builder.validateAndSet(SyncConfiguration.java:545)
at io.realm.SyncConfiguration$Builder.<init>(SyncConfiguration.java:458)
at io.realm.SyncConfiguration$Builder.<init>(SyncConfiguration.java:444)
at com.examkida.Activities.MainActivity$2.onSuccess(MainActivity.java:150)
at com.example.Activities.MainActivity$2.onSuccess(MainActivity.java:144)
at io.realm.SyncUser$Request$3.run(SyncUser.java:691)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6642)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)