项目中的Android Realm初始化 [英] Android Realm initialization in project
问题描述
在有关如何使用Realm的官方文档中可以看到
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"
我可以正常使用此库,但是静态方法init显然不存在.有人可以发布一个示例,说明如何使用此库将示例对象初始化并将其保存到数据库吗?确实没有太多的教程,并且在设法启动它之后,用法看起来非常简单.领域初始化设置默认配置对吗?那么有没有办法绕过该静态初始化并手动进行设置?
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?
-编辑
当我尝试执行此代码时
RealmConfiguration realmConfiguration = new RealmConfiguration.Builder(this).build();
我知道
错误:(33,49)错误:Builder(Context)在Builder中不是公共的;无法从外部软件包访问
Error:(33, 49) error: Builder(Context) is not public in Builder; cannot be accessed from outside package
推荐答案
此构造函数不再存在:
RealmConfiguration realmConfiguration = new RealmConfiguration.Builder(this).build();
改为使用此:
RealmConfiguration realmConfiguration = new RealmConfiguration.Builder().build();
您所引用的示例也应该已经更新?
The example you refer to should have been updated as well?
这篇关于项目中的Android Realm初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!