Firebase DatabaseException: Can’t convert object of type java.util.ArrayList to my type Object

I’m building an app in Android Studio and tried everything to read my database into the type Object I have set up and I’m stuck on this error, would really appreciate some help: Can’t convert object of type java.util.ArrayList to my type object.

This is my snapshot and eventlistener setup that is producing the error:

public class CountryDetailsActivity extends AppCompatActivity {

ListView lvCases;
List<CountryDetails> caseList;
DatabaseReference databaseCases;

protected void onCreate(Bundle savedInstanceState) {

    databaseCases = FirebaseDatabase.getInstance().getReference();
    lvCases = findViewById(;
    caseList = new ArrayList<CountryDetails>();

protected void onStart() {
    databaseCases.addValueEventListener(new ValueEventListener() {
        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
            for (DataSnapshot caseSnapshot : dataSnapshot.getChildren()) {
                CountryDetails cases = caseSnapshot.getValue(CountryDetails.class);

        public void onCancelled(@NonNull DatabaseError databaseError) { }

This is my CountryDetails class minus some setters and gettters:

String Country;
String NewConfirmed;
String NewDeaths;
String TotalConfirmed;
String TotalCases;
String TotalRecovered;

public CountryDetails() {

public CountryDetails(String Country, String NewConfirmed, String NewDeaths, String TotalConfirmed, String TotalCases, String TotalRecovered) {
    this.NewConfirmed = NewConfirmed;
    this.NewDeaths = NewDeaths;
    this.TotalConfirmed = TotalConfirmed;
    this.Country = Country;
    this.TotalCases = TotalCases;
    this.TotalRecovered = TotalRecovered;

public String getCountry() {
    return Country;

public void setCountry(String country) {
    Country = country;

And this is what my database structure looks like:

Where am I going wrong here?


I think you are having wrong reference if you are trying to fetch data of Countriesnode

Solution Code (add “Countries” in reference)

databaseCases = FirebaseDatabase.getInstance().getReference("Countries");