user1915767
user1915767

Reputation: 111

Realm Java prepackaged database

I am trying to put a preloaded Realm database in my app.

What I am doing:

  1. I created a simple app that loads data from JSON to the Realm database (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().

  3. After doing all this, when I try to do Realm.getInstance() then an empty Realm is returned.

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?

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?

Upvotes: 1

Views: 660

Answers (1)

geisshirt
geisshirt

Reputation: 2497

You say that your file is named default.realm and yet you refer to it as default1 in the snippet above. Does it work if you try with default?

Upvotes: 0

Related Questions