For my application, I added a ViewPager2 to show the recommended containing image, name, and country. But when I try to retrieve data from firebase this error shows. I tried tweaking the code but I think I'm only making it worse because the error is replaced by No setter/field for a class error. I have been stuck with the same error for a few days now and still can't solve it. I badly need help.
Below is my code for MainActivity
database = FirebaseDatabase.getInstance().getReference();
DatabaseReference myRef = database.child("Packages");
recommendList = new ArrayList<Recommendation>();
adapter = new RecommendAdapter(this, recommendList);
recommendViewPager.setAdapter(adapter);
setupRecommendViewPager();
myRef.addValueEventListener(new ValueEventListener() {
List<Recommendation> recommendList = new ArrayList<>();
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
for (DataSnapshot dataSnapshot : snapshot.getChildren()){
Recommendation recommendation = dataSnapshot.getValue(Recommendation.class);
//String recommendation = dataSnapshot.getValue(String.class);
recommendList.add(recommendation);
}
adapter.notifyDataSetChanged();
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
}
});
And this is my Recommendation.class
public class Recommendation {
public String package_attractions;
public String package_availability;
public String package_country;
public String package_description;
public String package_name;
public String package_photos;
public Double package_price;
public Double package_rating;
public String package_region;
public String package_video;
public Recommendation(){}
public Recommendation(String package_attractions, String package_availability, String package_country, String package_description, String package_name, String package_photos, Double package_price, Double package_rating, String package_region, String package_video) {
this.package_attractions = package_attractions;
this.package_availability = package_availability;
this.package_country = package_country;
this.package_description = package_description;
this.package_name = package_name;
this.package_photos = package_photos;
this.package_price = package_price;
this.package_rating = package_rating;
this.package_region = package_region;
this.package_video = package_video;
}
public String getPackage_attractions() {
return package_attractions;
}
public void setPackage_attractions(String package_attractions) {
this.package_attractions = package_attractions;
}
public String getPackage_availability() {
return package_availability;
}
public void setPackage_availability(String package_availability) {
this.package_availability = package_availability;
}
.........
And this is my firebase data
P.S I'm only retrieving photo, name, and country
