I am attempting to learn how to implement Firebase into an existing project that previously used a SQL db. I have the write code working correctly, but my read is throwing the DatabaseException error below.
com.google.firebase.database.DatabaseException: Found a conflicting setters with name: setWallpaper (conflicts with setWallpaper defined on android.content.ContextWrapper)
I have done a good bit of research and can only find references to this error when writing to the database, not reading from it, so I am very much confused as to what I might have done in my code to cause this error to happen. The method code is below.
protected void lastFive() {
final DatabaseReference gameRef = database.getReference("Games");
final List<User> gamesList = new ArrayList<>();
gameRef.orderByChild("Date").limitToLast(5).addValueEventListener (new ValueEventListener ( ) {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
gamesList.clear ();
for (DataSnapshot postSnapshot: dataSnapshot.getChildren ()){
User user = postSnapshot.getValue(User.class);
gamesList.add (user);
System.out.println(user.getName () + " : " + user.getScore ());
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
throw databaseError.toException();
}
});
}
The line in the method the error appears to be referencing is:
User user = postSnapshot.getValue(User.class);
I have only been working in Android for a couple months off and on, and Firebase less than half that, so it is possible there is some glaring error in this I simply do not see. FWIW, this method is intended to display the username and score for the last 5 games played on the app. I am a bit concerned what the output will look like, which I know is outside the scope of this question, but I am unable to even work on that until I can read the data. Any help or suggestion is greatly appreciated.
User code being added as requested.
public class User extends Application {
//private variable
private static User globalVar;
//variables
String _id;
String _name;
int _score;
String _date;
String _email;
// Empty constructor
public User(){}
// constructor
public User(String id, String name, int score, String date){
this._id = id;
this._name = name;
this._score = score;
this._date = date;
}
public User(String id, int score){
this._id = id;
this._score = score;
}
public User(String id){
this._id = id;
}
public User(int score, String date){
this._score = score;
}
// getting ID
public String getID(){
return this._id;
}
// setting id
public void setID(String id){
this._id = id;
}
// getting name
public String getName(){
return this._name;
}
// setting name
public void setName(String name){
this._name = name;
}
// getting scores
public int getScore(){ return this._score; }
// setting scores
public void setScore(int score){ this._score = score; }
// getting name
public String getDate(){
return this._date;
}
// setting name
public void setDate(String date){
this._date = date;
}
// getting email
public String getEmail(){
return this._email;
}
// setting email
public void setEmail(String email){
this._email = email;
}
public static synchronized User getGlobalVar(){
if(globalVar == null){
globalVar = new User();
}
return globalVar;
}
}