Search code examples
javaandroidfirebaseplaylist

Not able to add child to existing child in firebase android


I am creating a playlist app where every playlist has a unique key and have 2 child elements playlistId and playlist name. I want to add songs as a child under the playlist name.

Like this:

enter image description here

But this is what I am getting instead:

enter image description here

My code which brings the above-unwanted error prone result is -

 databaseReference = FirebaseDatabase.getInstance().getReference().child("a44f757c1f96ac85");

 public void saveSongsToPlayList(View view){
            try {
                String song = "Song";
               databaseReference.child(playListId).child(playListName)
                    .child("New song").child(song).setValue(song);
            }catch (Exception ex){
                ex.printStackTrace();
            }
    }

I don't think that I need to use the data snapshot for such a simple task. Or am I wrong?


Solution

  • Try this

         public void saveSongsToPlayList(View view){
                    try {
                       Firebase firebase = new Firebase("https://your-firebase-id.com").child("a44f757c1f96ac85").child("LZIZ......").child("playListName").child("NewSong")  
                       Firebase song1 = firebase.child("song")
                       song1.setValue("link to song or whatever")
                    }catch (Exception ex){
                        ex.printStackTrace();
                    }
            }