1

I want to write an ArrayList ArticleDesire of Article.Class inside a User of my database, my Article class has a String titre and an ArrayList motcle, in the database the motcle array won't show up in my Database i Checked and it wasn't empty Dataset

Here is my Add ArticleDesire Method

 public void addArticleDesire(final ArrayList<Article> motcle, String Userid)
    {
        mDatabase = FirebaseDatabase.getInstance().getReference("User");
        DatabaseReference user = mDatabase.child(Userid);
        final DatabaseReference keylist = user.child("ArticleDesire");
        keylist.setValue(motcle);
   }

My Article constructor

 public Article(ArrayList<String> arrayList, String titre) {
        if (arrayList.isEmpty()){
            Log.w("Arraylist","VIDE");
        }
        this.motcle=new ArrayList(arrayList);
        if (motcle.isEmpty()==false)
        {
            Log.w("Arraylist"," NON VIDE"+motcle);
        }
        this.titre=titre;
    }

I call the AddArticleDesire in an activity, I Checked the constructor when called and the ArrayList isn't empty and the articles are in it.
is it possible when having different constructors in the Article Class, it can interfere with the Writing?

1
  • can you show the complete code of your Article class and the part of your Activity, where you set up the ArrayLists and call addArticleDesire()? Commented May 9, 2018 at 7:52

1 Answer 1

1

Firebase Realtime Database doesn't store arrays. It stores sets of information(dictionaries/associate arrays). So the closest solution you can get is:

countries: {
  0: "Spain",
  1: "France",
  2: "Italy",
  3: "Poland",
  4: "Belgium"
}

So this should be the solution that you are looking for. If you wanna read more information and best practices regarding arrays in Realtime Database I suggest you to give a look to the next article: https://firebase.googleblog.com/2014/04/best-practices-arrays-in-firebase.html

Finally, if you recently started to work on your app and your database, I suggest you to switch it to Firestore, which allows you to store arrays: https://firebase.google.com/docs/firestore/solutions/arrays?hl=es-419

Sign up to request clarification or add additional context in comments.

1 Comment

Hi Fransisco. Your sign-off has some very kind wishes, but we prefer answers to focus on the technical material here. I often post the following advice for new users: We gently discourage greetings, hope-you-can-helps, thanks, advance thanks, notes of appreciation, regards, kind regards, signatures, please-can-you-helps, chatty material and abbreviated txtspk, pleading, how long you've been stuck, voting advice, meta commentary, etc. Just explain your problem, and show what you've tried, what you expected, and what actually happened.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.