realm / realm-java

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

Builder(android.content.Context) is not public in io.RealmConfigurationBuilder. Cannot be accesed from outside package #4010

Closed VilauGC closed 7 years ago

VilauGC commented 7 years ago

private void addAction() { // get the value of the 'goal' or 'to-do' // get the time when it was added String what = mInputWhat.getText().toString(); long now = System.currentTimeMillis(); RealmConfiguration configuration = new RealmConfiguration.Builder(getActivity()).build(); Realm.setDefaultConfiguration(configuration); Realm realm = Realm.getDefaultInstance(); Drop drop = new Drop(what, now, 0, false); realm.beginTransaction(); realm.copyToRealm(drop); realm.commitTransaction(); realm.close();

Zhuinden commented 7 years ago

Use new RealmConfiguration.Builder()

taha786 commented 7 years ago

i have the same issue and by using only new RealmConfiguration.Builder() it stills not working

Zhuinden commented 7 years ago

You also need to call Realm.init(Context) beforehand at some point

VilauGC commented 7 years ago

Hello! this is how i solved the problem :) I've created a new class that extends the Application because you need to pass an argument to the Realm.init() that is a context

public class AppBucketDrops extends Application { @Override public void onCreate() { super.onCreate(); Realm.init(this);

and i went to the manifest file and tag it another line :

<application

//this is the line i'm talking about android:name=".AppBucketDrops"

android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".ActivityMain">

and after all of this i went to the ActivityMain class inside onCreate(), and like this you wont need a configuration anymore.

@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mRealm = Realm.getDefaultInstance();

hope this was helpfull.

Best regards,

Vilau George

2017-01-27 20:05 GMT+02:00 taha786 notifications@github.com:

i have the same issue and by using only new RealmConfiguration.Builder() it stills not working

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/realm/realm-java/issues/4010#issuecomment-275731879, or mute the thread https://github.com/notifications/unsubscribe-auth/AT4b3UINNe-l_mVwHa0aq1QuIxUNWYQjks5rWjHkgaJpZM4Lfgu2 .

Zhuinden commented 7 years ago

I think you also need to call Realm.setDefaultConfiguration(), but yes

VilauGC commented 7 years ago

Well...they said that you don't need that anymore. So i haven't put it anywhere, and it still worked.

2017-01-27 20:55 GMT+02:00 Gabor Varadi notifications@github.com:

I think you also need to call Realm.setDefaultConfiguration(), but yes

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/realm/realm-java/issues/4010#issuecomment-275744305, or mute the thread https://github.com/notifications/unsubscribe-auth/AT4b3XC3FZLs-38MlGuTIU1V9VvHzE_uks5rWj21gaJpZM4Lfgu2 .

taha786 commented 7 years ago

thanks for everyone for helping me out

Best Taha Ahmad

On Sat, Jan 28, 2017 at 12:03 AM, George Ciprian Vilau < notifications@github.com> wrote:

Well...they said that you don't need that anymore. So i haven't put it anywhere, and it still worked.

2017-01-27 20:55 GMT+02:00 Gabor Varadi notifications@github.com:

I think you also need to call Realm.setDefaultConfiguration(), but yes

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub <https://github.com/realm/realm-java/issues/4010#issuecomment-275744305 , or mute the thread https://github.com/notifications/unsubscribe-auth/AT4b3XC3FZLs- 38MlGuTIU1V9VvHzE_uks5rWj21gaJpZM4Lfgu2 .

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/realm/realm-java/issues/4010#issuecomment-275746310, or mute the thread https://github.com/notifications/unsubscribe-auth/ATtVWQfXQMMtQoXAgvNfNjuFI9yibXfkks5rWj-JgaJpZM4Lfgu2 .

NikhilRPatil commented 7 years ago

he hi .... ciucurashu i have same problem which you explained above .... I am unable to put Realm.init() in my code so plz help me to slove it . In below i send u my git hub project link plz check and give me solutio

https://github.com/NikhilRPatil/Bucket_Drops/blob/master/app/src/main/java/com/example/nikhil007/bucketdrop/DialogAdd.java

Zhuinden commented 7 years ago

see https://github.com/realm/realm-java/issues/3472

VilauGC commented 7 years ago

Well after you followed the steps from above you should go inside your DialogAdd class inside the addAction() method and delete those two lines:

RealmConfiguration configuration.... And Realm.setDefault....

Only keep the Realm realm = Realm.getDefaultInstance()

This is what i remember doing. Unfortunately i've lost my code due to some hardware problem:)).

Pe 1 aug. 2017 09:35, "Gabor Varadi" notifications@github.com a scris:

see #3472 https://github.com/realm/realm-java/issues/3472

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/realm/realm-java/issues/4010#issuecomment-319281519, or mute the thread https://github.com/notifications/unsubscribe-auth/AT4b3SXO3QVQXc0c5g__M4zMMT1erDj8ks5sTsdLgaJpZM4Lfgu2 .