Reputation: 41
No setter/field for Zone found on class com.food.app.Chef
No setter/field for Province found on class com.food.app.Chef
Hi everyone I try to retrieve data from Firebase dataset and I keep getting this error even tho I tried every single solution from StackOverflow and what I was able to find on Google but without any benefit
Below I will link the Activity and the Class and the datasets
Model Class '''
public class Chef {
private String Area,City, ConfirmPassword,EmailID,Fname,House,Lname,Mobile,Password,Postcode,Province,Zone;
public Chef(){
}
public Chef(String area, String city, String confirmPassword, String emailID, String fname, String house, String lname, String mobile, String password, String postcode, String province, String zone) {
Area = area;
City = city;
ConfirmPassword = confirmPassword;
EmailID = emailID;
Fname = fname;
House = house;
Lname = lname;
Mobile = mobile;
Password = password;
Postcode = postcode;
Province = province;
Zone = zone;
}
public String getArea() {
return Area;
}
public String getSuburban() {
return City;
}
public String getConfirmPassword() {
return ConfirmPassword;
}
public String getEmailID() {
return EmailID;
}
public String getFname() {
return Fname;
}
public String getHouse() {
return House;
}
public String getLname() {
return Lname;
}
public String getMobile() {
return Mobile;
}
public String getPassword() {
return Password;
}
public String getPostcode() {
return Postcode;
}
public String getCity() {
return Province;
}
public String getState() {
return Zone;
}
}
'''
Code for getting data
dataaa = FirebaseDatabase.getInstance().getReference("Supplier").child(userid);
dataaa.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
Chef chefc = dataSnapshot.getValue(Chef.class);
State = chefc.getState();
City = chefc.getCity();
Sub = chefc.getSuburban();
Log.d("ChefHomeFragment", "State: "+State);
Log.d("ChefHomeFragment", "City: "+City);
Log.d("ChefHomeFragment", "Sub: "+Sub);
chefDishes();
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
Log output
W/ClassMapper: No setter/field for Zone found on class com.TUAAM.app.Chef
No setter/field for Province found on class com.TUAAM.app.Chef
D/ChefHomeFragment: State: null
City: null
Sub: Chitral
D/AndroidRuntime: Shutting down VM
DataBase
"Supplier" : {
"QrpG38UhbkVnkiTQ2it5MzPS2u42" : {
"Area" : "",
"City" : "Chitral",
"ConfirmPassword" : "",
"EmailID" : "",
"Fname" : "",
"House" : "",
"Lname" : "",
"Mobile" : "",
"Password" : "",
"Postcode" : "",
"Province" : "KP",
"Zone" : "North"
}
},
Upvotes: 1
Views: 780
Reputation: 599206
The error is caused by the fact that there is no public way for Firebase to set the value of Province
(and other fields) in your class. To fix this, you can either add setters as Kamal answered, or alternatively, you can mark the member fields themselves as public:
public class Chef {
public String Area,City, ConfirmPassword,EmailID,Fname,House,Lname,Mobile,Password,Postcode,Province,Zone;
...
In fact, if you mark the member fields as public like above, you don't even need getters either. So when I'm just getting started, I often end up with Java classes that only have fields, and some constructors to make it easy to create them from my own code. In your code, the minimum could be:
public class Chef {
public String area, city, confirmPassword, emailID, fname, fouse, lname, mobile, password, postcode, province, zone;
public Chef(){
}
public Chef(String area, String city, String confirmPassword, String emailID, String fname, String house, String lname, String mobile, String password, String postcode, String province, String zone) {
this.area = area;
this.ity = city;
this.confirmPassword = confirmPassword;
this.emailID = emailID;
this.fname = fname;
this.house = house;
this.lname = lname;
this.mobile = mobile;
this.password = password;
this.postcode = postcode;
this.province = province;
this.zone = zone;
}
}
You'll note that I've changed the casing of the member fields here, as Firebase will use the "raw" names of the fields for the property names in the database in this case.
Upvotes: 0
Reputation: 1718
You need to create setters for these fields.
Updated Model Class: and if the problem persists then you can use HashMap<String, Object> map; and store values in it.
public class Chef {
private String Area,City, ConfirmPassword,EmailID,Fname,House,Lname,Mobile,Password,Postcode,Province,Zone;
public Chef() {
}
public String getArea() {
return Area;
}
public void setArea(String area) {
Area = area;
}
public String getCity() {
return City;
}
public void setCity(String city) {
City = city;
}
public String getConfirmPassword() {
return ConfirmPassword;
}
public void setConfirmPassword(String confirmPassword) {
ConfirmPassword = confirmPassword;
}
public String getEmailID() {
return EmailID;
}
public void setEmailID(String emailID) {
EmailID = emailID;
}
public String getFname() {
return Fname;
}
public void setFname(String fname) {
Fname = fname;
}
public String getHouse() {
return House;
}
public void setHouse(String house) {
House = house;
}
public String getLname() {
return Lname;
}
public void setLname(String lname) {
Lname = lname;
}
public String getMobile() {
return Mobile;
}
public void setMobile(String mobile) {
Mobile = mobile;
}
public String getPassword() {
return Password;
}
public void setPassword(String password) {
Password = password;
}
public String getPostcode() {
return Postcode;
}
public void setPostcode(String postcode) {
Postcode = postcode;
}
public String getProvince() {
return Province;
}
public void setProvince(String province) {
Province = province;
}
public String getZone() {
return Zone;
}
public void setZone(String zone) {
Zone = zone;
}
}
and I couldn't understand that why are you returning Province in getCity().
Upvotes: 1