我是Realm的新手。我在领域服务器上对不同用户的身份验证有困难。 我写了几行代码来测试后续登录到服务器和域分离。
*java.lang.IllegalArgumentException: Configurations cannot be different if used to open the same file.
Cached configuration:
realmDirectory: /data/user/0/com.my.assistant/files/realm-object-server/621c2e6db5e0cf421741f6e9a428c3dc/621c2e6db5e0cf421741f6e9a428c3dc
realmFileName : default
canonicalPath: /data/data/com.my.assistant/files/realm-object-server/621c2e6db5e0cf421741f6e9a428c3dc/621c2e6db5e0cf421741f6e9a428c3dc/default
key: [length: 0]
schemaVersion: 0
migration: null
deleteRealmIfMigrationNeeded: false
durability: FULL
schemaMediator: io.realm.DefaultRealmModuleMediator@5208266
readOnly: false
compactOnLaunch: null
serverUrl: realm://localhost:9080/621c2e6db5e0cf421741f6e9a428c3dc/default
user: {UserId: 621c2e6db5e0cf421741f6e9a428c3dc, AuthUrl: http://localhost:9080/auth, IsValid: false, Sessions: 0}
errorHandler: com.my.assistant.LoginInstrTest2$1@397b523
deleteRealmOnLogout: false
waitForInitialRemoteData: false
New configuration:
realmDirectory: /data/user/0/com.my.assistant/files/realm-object-server/621c2e6db5e0cf421741f6e9a428c3dc/621c2e6db5e0cf421741f6e9a428c3dc
realmFileName : default
canonicalPath: /data/data/com.my.assistant/files/realm-object-server/621c2e6db5e0cf421741f6e9a428c3dc/621c2e6db5e0cf421741f6e9a428c3dc/default
key: [length: 0]
schemaVersion: 0
migration: null
deleteRealmIfMigrationNeeded: false
durability: FULL
schemaMediator: io.realm.DefaultRealmModuleMediator@5208266
readOnly: false
compactOnLaunch: null
serverUrl: realm://localhost:9080/621c2e6db5e0cf421741f6e9a428c3dc/default
user: {UserId: 621c2e6db5e0cf421741f6e9a428c3dc, AuthUrl: http://localhost:9080/auth, IsValid: true, Sessions: 0}
errorHandler: com.my.assistant.LoginInstrTest2$1@cdafa20
deleteRealmOnLogout: false
waitForInitialRemoteData: false
at io.realm.RealmCache.validateConfiguration(RealmCache.java:461)
at io.realm.RealmCache.doCreateRealmOrGetFromCache(RealmCache.java:337)
at io.realm.RealmCache.createRealmOrGetFromCache(RealmCache.java:284)
at io.realm.Realm.getInstance(Realm.java:301)
at com.my.assistant.LoginInstrTest2.setConfigurationSyncUser(LoginInstrTest2.java:149)
at com.my.assistant.LoginInstrTest2.loginUser(LoginInstrTest2.java:129)
at com.my.assistant.LoginInstrTest2.veryfyRealmUserInstance(LoginInstrTest2.java:98)
at java.lang.reflect.Method.invoke(Native Method)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:59)
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:262)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2074)*
有人可以告诉我为什么吗?我对此代码的意图是使用realm测试android应用程序的胚胎登录/注销。用户应使用不同的凭据登录和退出应用程序。对我来说听起来应该有一种方法来为该用户获取以前创建的SyncConfiguration而不是创建一个新的...但是,如果是这种情况,我不知道该怎么做......。
这是我的代码:
// -----------主要代码:
SyncUser userLogged;
//Login with first user. This time the login completes successfully
userLogged = loginUser("pluto@qui.li", "pluto");
insertUserAppSyncRealm();
RealmResults<UserApp> res = realm.where(UserApp.class)
.beginsWith("username", "situs")
.findAll();
System.out.println(" @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Size table pippo " + res.size());
UserApp resUser = res.last();
System.out.println(" @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ID " + resUser.getId());
userLogged.logout();
//Login with second user OK
userLogged = loginUser("paperino@qui.li", "paperino");
RealmResults<UserApp> res2 = realm.where(UserApp.class)
.beginsWith("username", "situs")
.findAll(); //arrivato qui da "Configurations cannot be different if used to open the same file"
System.out.println(" @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Size table usertest " + res2.size());
userLogged.logout();
//Login again with first user. This time the login fails ("Configurations cannot be different if used to open the same file")
userLogged = loginUser("pluto@qui.li", "pluto");
RealmResults<UserApp> res3 = realm.where(UserApp.class)
.beginsWith("username", "situs")
.findAll();
System.out.println(" @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Size table pippo " + res3.size());
userLogged.logout();
// -----------使用过的函数:
public SyncUser loginUser(String username, String password) {
SyncUser userLogged;
SyncCredentials myCredentials = SyncCredentials.usernamePassword(username, password, false);
userLogged = SyncUser.login(myCredentials, authURL);
setConfigurationSyncUser(userLogged);
return userLogged;
}
public void setConfigurationSyncUser(SyncUser user) {
String user1RealmUrl = "realm://localhost:9080/~/default";
SyncConfiguration config = new SyncConfiguration.Builder(user, user1RealmUrl).
errorHandler(new SyncSession.ErrorHandler() {
public void onError(SyncSession session, ObjectServerError error) {
fail("Realm unexpected error: " + error);
}
})
.build();
realm = Realm.getInstance(config); //fails ("Configurations cannot be different if used to open the same file")
}
public void insertUserAppSyncRealm() {
UserApp user = new UserApp();
populateUser(user);
realm.beginTransaction();
realm.insert(user);
realm.commitTransaction();
}
private void populateUser(UserApp user) {
user.setUsername("situs@qui.it");
user.setPassword("12345678");
user.setId(UUID.randomUUID().toString());
}
提前感谢你的善意......
答案 0 :(得分:1)
您可以尝试以下代码:
<meta http-equiv="X-UA-Compatible" content="IE=8" />