realm / realm-java

Realm is a mobile database: a replacement for SQLite & ORMs
http://realm.io
Apache License 2.0
11.45k stars 1.75k forks source link

Hi @rzong...You can use `RealmConfiguration.Builder.directory()` and `RealmConfiguration.Builder.name()` to set a path to a Realm file. #7794

Closed Huazhiling closed 1 year ago

Huazhiling commented 1 year ago

Hi @rzong...You can use RealmConfiguration.Builder.directory() and RealmConfiguration.Builder.name() to set a path to a Realm file.

Originally posted by @cmelchior in https://github.com/realm/realm~~java/issues/7668#issuecomment~~1094704938

I have a problem with creating by this method,

Unrecoverable error. Invalid argument in /home/cc/repo/realm/release/realm/realm-library/src/main/cpp/io_realm_internal_SharedRealm.cpp line 217

version:3.1.1

clementetb commented 1 year ago

@Huazhiling We would need some context on what are you trying to do, could you please share the initialization code for your Realm?

Are you using version Realm3.1.1, try to upgrade to the latest version.

Huazhiling commented 1 year ago

@Huazhiling We would need some context on what are you trying to do, could you please share the initialization code for your Realm?

Are you using version Realm3.1.1, try to upgrade to the latest version.

Realm.init(this);
        // setting realm config
        RealmConfiguration config = new RealmConfiguration.Builder()
                .deleteRealmIfMigrationNeeded()
                .name("MISUMIRealm.realm")
                .schemaVersion(1)
                .migration(new MyMigration())
                .build();
        // save default config
        Realm.setDefaultConfiguration(config);

I get an error when calling

Realm.getDefaultInstance()

I can't upgrade to the latest version right now, My current project is relatively old and cannot support androidx for the time being. The latest version requires kontlinx.flow and needs to be upgraded to androidx, which cannot be upgraded

clementetb commented 1 year ago

Version 10.13.1 does not require kotlinx.flow. It might require some changes though.

The Realm Version 3.1.1 is 6 years old and since we have released many new features and bug fixes.

Huazhiling commented 1 year ago

Version 10.13.1 does not require kotlinx.flow. It might require some changes though.

The Realm Version 3.1.1 is 6 years old and since we have released many new features and bug fixes.

Hi,Now this problem arises

java.lang.UnsupportedOperationException

The coroutines framework is missing from the classpath. Remember to add it as an implementation dependency. See https://github.com/Kotlin/kotlinx.coroutines#android for more details

 com.alibaba.fastjson.JSONException: write javaBean error

I need to parse the data returned by Realm into a string and return it, but when using FastJSON for parsing, an error occurred due to one of the returned values having a type of "flow", which is not compliant with FastJSON's parsing rules. This error did not occur in older versions.

clementetb commented 1 year ago

@Huazhiling I am glad that you were able to resolve the first issue.

Now the issue is that you are trying to use coroutine-based Realm helper methods, but you can not provide the coroutines library.

Avoid using such helper methods and you would be safe. I am afraid that if you like to use such methods you would need to migrate to use androidx.

Huazhiling commented 1 year ago

@Huazhiling I am glad that you were able to resolve the first issue.

Now the issue is that you are trying to use coroutine-based Realm helper methods, but you can not provide the coroutines library.

Avoid using such helper methods and you would be safe. I am afraid that if you like to use such methods you would need to migrate to use androidx.

Okay, since upgrading is not possible for this old project and that method is necessary, I will stick with the previous version of Realm. Thank you for your help.

clementetb commented 1 year ago

Those methods are not available in the previous version of Realm, how isn't it an issue?

Huazhiling commented 1 year ago

Those methods are not available in the previous version of Realm, how isn't it an issue?

I don't know which methods you mentioned, is it directory() or name()? This was available in the previous version. I took a look at the code of this version. There is no Flow related, only rx, and the new version adds Flow.

rorbech commented 1 year ago

Hi @Huazhiling. It is a bit hard to understand the issue here. Seems like the original question was about directory and name. If you have other issues (upgrading, other APIs, etc.), please open a new issue with the exact description:

Please include code and log snippets to make intention and observations more clear.

github-actions[bot] commented 1 year ago

This issue has been automatically closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don't have enough information to take action. Please reach out if you have or find the answers we need so that we can investigate further.