M Tomczynski
M Tomczynski

Reputation: 15714

Android Realm initialization in project

As seen in the official documentation on how to use Realm

// Initialize Realm
Realm.init(context);

// Get a Realm instance for this thread
Realm realm = Realm.getDefaultInstance();

I added dependencie to my project

classpath "io.realm:realm-gradle-plugin:2.0.2"

I can use this library normally but static method init apparently does not exist. Can someone post an example of how to initialize and save example object to database using this library? There's really not too many tutorials and the usage looks really easy after you manage to fire it up. Realm initialization sets up default configuration right? So is there a way to bypass that static init and set it manually?

--EDIT

When I'm trying to execute this code

RealmConfiguration realmConfiguration = new RealmConfiguration.Builder(this).build();

I get

Error:(33, 49) error: Builder(Context) is not public in Builder; cannot be accessed from outside package

Upvotes: 12

Views: 7541

Answers (2)

M Tomczynski
M Tomczynski

Reputation: 15714

For me the actual problem was that Android studio couldn't update the library from some old version I initially connected to the project. Gradle had good version but actual libs files were old, solution for me was to manually re-download the files of this library.

Upvotes: 0

Christian Melchior
Christian Melchior

Reputation: 20126

This constructor no longer exists:

RealmConfiguration realmConfiguration = new RealmConfiguration.Builder(this).build();

Use this instead:

RealmConfiguration realmConfiguration = new RealmConfiguration.Builder().build();

The example you refer to should have been updated as well?

Upvotes: 33

Related Questions