Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 261
M Tomczynski Avatar asked Oct 11 '16 07:10

M Tomczynski


1 Answers

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?

like image 181
Christian Melchior Avatar answered Nov 16 '22 20:11

Christian Melchior