简体   繁体   English

Realm Java预打包数据库

[英]Realm Java prepackaged database

I am trying to put a preloaded Realm database in my app. 我试图在我的应用程序中放入预加载的Realm数据库。

What I am doing: 我在做什么:

  1. I created a simple app that loads data from JSON to the Realm database (default1.realm). 我创建了一个简单的应用程序,可将数据从JSON加载到Realm数据库(default1.realm)。

  2. I have my actual app, where I am trying to put the default.realm file created by the loader in the res/raw folder and using the Migration Examples copyBundledRealmFile() function to copy default.realm to getFilesDir(). 我有一个实际的应用程序,我试图将由加载程序创建的default.realm文件放在res / raw文件夹中,并使用“迁移示例” copyBundledRealmFile()函数将default.realm复制到getFilesDir()。

  3. After doing all this, when I try to do Realm.getInstance() then an empty Realm is returned. 完成所有这些操作后,当我尝试执行Realm.getInstance()时,将返回一个空的Realm。

What am I doing wrong? 我究竟做错了什么?

String path3 = copyBundledRealmFile(this.getResources().openRawResource(R.raw.default1), "default.realm");

Realm r1 = Realm.getInstance(this);

r1 should point to the file I copied, right? r1应该指向我复制的文件,对吗?

UPDATE: I found why I could not access the database: 更新:我发现了为什么我无法访问数据库:

03-27 10:27:50.965  17750-17750/? A/art﹕ art/runtime/check_jni.cc:65] JNI DETECTED ERROR IN APPLICATION: 
input is not valid Modified UTF-8: illegal continuation byte 0x2e
03-27 10:27:50.965  17750-17750/? A/art﹕ art/runtime/check_jni.cc:65]     string: 'Unspecified exception. 
Failure when converting long string to UTF-16 error_code = 2; retcode = 0; StringData.size = 40487; StringData.data = etc..

03-27 10:27:50.965  17750-17750/? A/art﹕ art/runtime/check_jni.cc:65] JNI DETECTED ERROR IN APPLICATION: 
input is not valid Modified UTF-8: illegal continuation byte 0x2e
03-27 10:27:50.965  17750-17750/? A/art﹕ art/runtime/check_jni.cc:65]     string: 'Unspecified exception. 
Failure when converting long string to UTF-16 error_code = 2; retcode = 0; StringData.size = 40487; StringData.data =

My question would be now why is this error happening? 我的问题是现在为什么会发生此错误?

You say that your file is named default.realm and yet you refer to it as default1 in the snippet above. 您说您的文件名为default.realm ,但在上面的代码段中将其称为default1 Does it work if you try with default ? 如果您尝试使用default是否可行?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM