Я пытаюсь извлечь данные из базы данных Firebase в реальном времени в мое приложение, когда приведение объекта данных с классом pojo я получаю, пожалуйста, помогите мне
Вот данные в формате json, которые я пытаюсь получить из базы данных. Это массив json, который содержит названия стран и радиостанции aaray в соответствующей стране
[ {
"country" : "india",
"station" : [ {
"image" : "https://firebasestorage.googleapis.com/v0/b/testing-radio-app.appspot.com/o/RadioUi%2F1.jpg?alt=media&token=1ff817e1-7caa-4074-927e-dfca0f7b49aa",
"title" : "India1",
"url" : "http://prclive1.listenon.in:9960"
}, {
"image" : "https://firebasestorage.googleapis.com/v0/b/testing-radio-app.appspot.com/o/RadioUi%2F2.jpg?alt=media&token=cb03a047-f51c-478d-8b0c-26379adba9a1",
"title" : "India2",
"url" : "http://192.240.102.133:11454/stream"
} ]
}, {
"country" : "us",
"station" : [ {
"image" : "https://firebasestorage.googleapis.com/v0/b/testing-radio-app.appspot.com/o/RadioUi%2Fmango.png?alt=media&token=ee11dcab-7ce4-4057-b045-2107b07bc97a",
"title" : "US1",
"url" : "http://7619.live.streamtheworld.com:3690/977_HITS_SC"
} ]
} ]
**// here is my java code in side mainActivity here is firebase code**
DatabaseReference database =
FirebaseDatabase.getInstance().getReference();
database.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
**//here im getting all country array**
Iterable<DataSnapshot> contact = dataSnapshot.getChildren();
for (DataSnapshot d:contact)
{
**//here im trying to read array data one by one and type cast it with pojo class but on this line im getting run time exception**
Response res= d.getValue(Response.class);
Log.d("data", "onDataChange: "+res.toString());
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
**these are my two pojo classes
1.Station.java class contains radio station name, image, and url**
public class Station
{
private String image;
private String title;
private String url;
public String getImage ()
{
return image;
}
public void setImage (String image)
{
this.image = image;
}
public String getTitle ()
{
return title;
}
public void setTitle (String title)
{
this.title = title;
}
public String getUrl ()
{
return url;
}
public void setUrl (String url)
{
this.url = url;
}
@Override
public String toString()
{
return "ClassPojo [image = "+image+", title = "+title+", url = "+url+"]";
}
**2.Response.java class which contains conutry name and station array**
public class Response
{
private String country;
private Station[] station;
public String getCountry ()
{
return country;
}
public void setCountry (String country)
{
this.country = country;
}
public Station[] getStation ()
{
return station;
}
public void setStation (Station[] station)
{
this.station = station;
}
@Override
public String toString()
{
return "ClassPojo [country = "+country+", station = "+station+"]";
}
}
Я получаю это исключение
com.google.firebase.database.DatabaseException: преобразование в массивы не поддерживается, используйте Listsinstead
Я хочу получить все данные о стране и ее станциях в одном массиве arrayList, но из-за этого исключения я не могу это сделать, пожалуйста, помогите мне. Заранее спасибо