Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 384
MADMVX Avatar asked Feb 14 '17 23:02

MADMVX


3 Answers

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);
like image 187
Jagandeep Singh Avatar answered Nov 07 '22 01:11

Jagandeep Singh


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);
}
like image 20
Sergey Bubenshchikov Avatar answered Nov 07 '22 00:11

Sergey Bubenshchikov


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

RealmConfiguration config = new RealmConfiguration.Builder().deleteRealmIfMigrationNeeded().build();
like image 2
Jesse Buss Avatar answered Nov 07 '22 00:11

Jesse Buss