2 / 11
Nov 2023

I’m using this code to get Realm Instance on MainActivity:

App app = new App(new AppConfiguration.Builder("application-0-vaocb").build()); SyncConfiguration config = new SyncConfiguration.Builder(app.currentUser()).build(); Realm realm = Realm.getInstance(config);

And using the exact same code on another activity CustomerActivity:

App app = new App(new AppConfiguration.Builder("application-0-vaocb").build()); SyncConfiguration config = new SyncConfiguration.Builder(app.currentUser()).build(); Realm realm = Realm.getInstance(config);

Still getting this error:

java.lang.IllegalArgumentException: Configurations cannot be different if used to open the same file. Cached configuration: realmDirectory: /data/user/0/com.in/files/mongodb-realm/application-0/65566a52ab8ce3e71ebdcf22 realmFileName : default.realm canonicalPath: /data/user/0/com.in/files/mongodb-realm/application-0/65566a52ab8ce3e71ebdcf22/default.realm key: [length: 0] schemaVersion: 0 migration: null deleteRealmIfMigrationNeeded: false durability: FULL schemaMediator: io.realm.DefaultRealmModuleMediator@fcf6dfb readOnly: false compactOnLaunch: null maxNumberOfActiveVersions: 9223372036854775807 serverUrl: wss://realm.mongodb.com/ user: io.realm.mongodb.User@95acac88 errorHandler: io.realm.mongodb.AppConfiguration$Builder$1@fcda401 initialSubscriptions: null deleteRealmOnLogout: false syncClientValidateSsl: true serverCertificateAssetName: null serverCertificateFilePath: null waitForInitialData: false initialDataTimeoutMillis: 9223372036854775807 sessionStopPolicy: AFTER_CHANGES_UPLOADED syncUrlPrefix: /api/client/v2.0/app/application-0-vaocb/realm-sync partitionValue: null New configuration: realmDirectory: /data/user/0/com.in/files/mongodb-realm/application-0/65566a52ab8ce3e71ebdcf22 realmFileName : default.realm canonicalPath: /data/user/0/com.in/files/mongodb-realm/application-0/65566a52ab8ce3e71ebdcf22/default.realm key: [length: 0] schemaVersion: 0 migration: null deleteRealmIfMigrationNeeded: false durability: FULL schemaMediator: io.realm.DefaultRealmModuleMediator@fcf6dfb readOnly: false compactOnLaunch: null maxNumberOfActiveVersions: 9223372036854775807 serverUrl: wss://realm.mongodb.com/ user: io.realm.mongodb.User@e4199dbc errorHandler: io.realm.mongodb.AppConfiguration$Builder$1@7bbf883 initialSubscriptions: null deleteRealmOnLogout: false syncClientValidateSsl: true serverCertificateAssetName: null serverCertificateFilePath: null waitForInitialData: false initialDataTimeoutMillis: 9223372036854775807 sessionStopPolicy: AFTER_CHANGES_UPLOADED syncUrlPrefix: /api/client/v2.0/app/application-0-vaocb/realm-sync partitionValue: null

Here is the diffchecker screenshot:

It looks like the error handler registration counts towards the hash of the configuration. Try removing the error handler…

19 days later

Hi @Sajjad_Amini and @Arturo_Martinez ,

We don’t know whether the problem in the description was solved, as the OP never replied to our suggestion (i.e. only use ONE app, don’t re-create the app every time you try to access the DB, as that can leave around multiple users that would conflict when accessing the same DB)

1 year later