I want retrieve a video url from Firebase realtime database, but the url is null.
This is my database:
The video is located in the Firebase Storage. If I search the URL, Google finds it
This is my code:
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
listaEsercizi.clear();
for (DataSnapshot snapshot: dataSnapshot.getChildren()) {
String nome = snapshot.getValue(Esercizio.class).getNome();
String video = snapshot.getValue(Esercizio.class).getVideoURI().toString();
listaEsercizi.add(new Esercizio(video, nome));
}
So, the string in "nome" is "Parallele", but the string in "video" is null.
From the debug I realized that in "getVideoUri().toString()" exist the URL, but lost in assignment.
CodePudding user response:
Your naming for your Video
is not match as the database.
Change from:
private String videoURI;
//Here is video getset
To:
private String video;
//Here is video getset
And then, you can call them like this:
String nome = snapshot.getValue(Esercizio.class).getNome();
String video = snapshot.getValue(Esercizio.class).getVideo();
listaEsercizi.add(new Esercizio(video, nome));