Builder (android.content.Context)' is not public in 'io.realm.RealmConfiguration.Builder'. Cannot be accessed from outside package

10,727

Solution 1

If I'm not mistaken, since version 2 of Realm you need pass context to Ream by call init() method.

  1. you need to call init() of Realm
  2. you can build you realm configuration

private void setUpRealmConfig(){

    // initialize Realm
    Realm.init(getApplicationContext());

    // create your Realm configuration
    RealmConfiguration config = new RealmConfiguration.
                                   Builder().
                                   deleteRealmIfMigrationNeeded().
                                   build();
    Realm.setDefaultConfiguration(config);
}

Solution 2

In Realm, we don't pass any parameter to Builder.To set Realm configuration setting we simply call Builder initialization.

For eg:-

    Realm.init(getApplicationContext());

    RealmConfiguration realmConfiguration = new RealmConfiguration.Builder()
                .name(Realm.DEFAULT_REALM_NAME)
                .schemaVersion(0)
                .deleteRealmIfMigrationNeeded()
                .build();
    Realm.setDefaultConfiguration(realmConfiguration);

Solution 3

It looks like that constructor is deprecated. Try using this one instead:

RealmConfiguration config = new RealmConfiguration.Builder().deleteRealmIfMigrationNeeded().build();

Solution 4

In order to set configuration of Realm, do the following in your Application.class

private void initRealm() {

    // initialize realm
    Realm.init(getApplicationContext());

    // create realm configuration
    RealmConfiguration defaultConfig = new RealmConfiguration.Builder()
            .schemaVersion(0)
            .migration(new RealmLocalMigration())
            .build();
    Realm.setDefaultConfiguration(defaultConfig);

}
Share:
10,727
MADMVX
Author by

MADMVX

Java developer

Updated on June 09, 2022

Comments

  • MADMVX
    MADMVX almost 2 years

    And add the dependencies and plugins everything is fine but when I put this

     private void setUpRealmConfig(){
    
    
        RealmConfiguration config = new RealmConfiguration.Builder(getApplicationContext()).deleteRealmIfMigrationNeeded().build();
        Realm.setDefaultConfiguration(config);
    }
    

    in the part of = RealmConfiguration.Builder. I get this error:

    Builder(android.content.Context)' is not public in 'io.realm.RealmConfiguration.Builder'. Cannot be accessed from outside package

    and I do not know what to do.