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

走远了吗. 提交于 2019-12-23 09:58:52

问题


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"


回答1:


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



回答2:


You have to get reference to your node:

DatabaseReference mDatabaseReference = FirebaseDatabase.getInstance().getReference().child("Your Node Name");


来源:https://stackoverflow.com/questions/38572640/no-setter-field-for-while-trying-to-populate-a-listview-on-firebase

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!