Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No setter/field for while trying to populate a listview on firebase

I am trying to retrieve data from firebase and display it on my listview using firebase-ui. The code runs fine but nothing is displayed on the list view. This is what I get from my logs:

W/ClassMapper: No setter/field for -KNRXdDOlA9nV6qxXvOl found on class com.example.sammie.coreteccontacts.Sacco

Here is my FirebaselistAdapter

DatabaseReference mDatabaseReference = FirebaseDatabase.getInstance().getReference();
FirebaseListAdapter<Sacco> adapter = new FirebaseListAdapter<Sacco>(getActivity(), Sacco.class, android.R.layout.simple_list_item_1, mDatabaseReference) {
 @Override
protected void populateView(View view, Sacco sacco, int i) {
((TextView)view.findViewById(android.R.id.text1)).setText(Sacco.getName());
}
};
contactList.setAdapter(adapter);

Here is my Sacco class:

package com.example.sammie.coreteccontacts;

public class Sacco {

    String description;
    String location;
    static String name;

    public Sacco() {
    }

    public Sacco(String description, String location, String name) {
        this.name = name;
        this.description = description;
        this.location = location;
    }

    public static String getName() {
        return name;
    }

    public String getDescription() {
        return description;
    }

    public String getLocation() {
        return location;
    }
}

Here is a sample of the data from firebase

KNRWnG6BTkbGJQJVq9Qaddclose

description:"test description"

location: "test location"

name: "test name"

like image 964
Noel Omondi Avatar asked Jul 25 '16 16:07

Noel Omondi


People also ask

How do I add a listview to a firebase activity?

Make sure your ListView has an id, then create a reference to it in your Activity and set its adapter to a new FirebaseListAdapter: After you've done that, add some data to your database and watch the ListView populate itself.

How to read data from Firebase FireStore in Java?

For reading data from the Firebase Firestore database, we have to create an Object class and we will read data inside this class. For creating an object class, navigate to the app > java > your app’s package name > Right-click on it and click on New > Java Class > Give a name to your class.

How do I add firebase to my Android app?

You’ll need to head over to Firebase Console, create app, then download configuration file and add to your project in the app folder.You also have to allow writes and reads from the FirebaseDatabase without authentication. Example 4: Android Firebase ListView – Write, Read, Scroll to Last Added Item

How to show listview from FireStore in flutter?

When trying to show a ListView from Firestore, in Flutter we have 2 options. We can either use FutureBuider or StreamBuilder . If we use StreamBuilder, the data on the List Will updately realtime.


1 Answers

There are no setter methods in your class.

public void setName(String name) {
    this.name = name;
}

public void setDescription(String description) {
    this.description = description;
}

public void setLocation(String location) {
    this.location = location;
}

BUT

-KNRWnG6BTkbGJQJVq9Qaddclose

This is a unique key which is to be obtained as an object containing your description, location and name.

W/ClassMapper: No setter/field for -KNRXdDOlA9nV6qxXvOl found on class com.example.sammie.coreteccontacts.Sacco

This shows that there is an error with your database listener's positioning. It is reading -KNRWnG6BTkbGJQJVq9Qaddclose as a variable to your Sacco class instead of an object of it.

Please check the JSON file and DatabaseReference. Most probably it should be like this:

  • UnderChilds <----- (ON CHILD LISTENER).
    • -KNRWnG6BTkbGJQJVq9Qaddclose
    • -KNRWnSYnuojkbGJQJVq9Qaddclos
like image 95
Tanishq Sharma Avatar answered Sep 18 '22 08:09

Tanishq Sharma