Мое приложение выдает следующую ошибку: com.google.firebase.database.DatabaseException: Failed to convert value of type java.lang.Long to String
Эта ошибка возникает в строке: mGame = dataSnapshot.getValue(Game.class) Вот мой код:
//create datarefence of only 1 game namely the current game
specificGameRef =mDatabase.child("games").child(-KhmBnF9vTLJSgNBcPqE);
specificGameRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
mGame =dataSnapshot.getValue(Game.class);
}
@Override
public void onCancelled(DatabaseError databaseError) {
// Getting Post failed, log a message
Log.w(TAG, "loadPost:onCancelled", databaseError.toException());
// ...
}
});
Вот мой код json из базы данных firebase:
Если кто-то может помочь мне найти мою ошибку, спасибо.
EDIT: Класс игры:
public class Game {
//firebase
private FirebaseAuth mAuth;
private FirebaseAuth.AuthStateListener mAuthListener;
private DatabaseReference mDatabase;
FirebaseUser user;
User mUser;
private String creatorName;
private String key;
private int day;
private int month;
private int year;
private int clockHours;
private int clockMinutes;
private int durationMin;
private int durationMax;
private String creatorId;
public Game() //An empty constructor for datastorage of Firebase
{
}
public Game(String creatorId) {
this.creatorId = creatorId;
key = getKey();
day = getDay();
month = getMonth();
year = getYear();
clockHours = getClockHours();
clockMinutes = getClockMinutes();
durationMin = getDurationMin();
durationMax = getDurationMax();
}
EDIT: класс пользователя
public class User {
//firebase authentification system
private FirebaseAuth mAuth;
private FirebaseAuth.AuthStateListener mAuthListener;
private DatabaseReference mDatabase;
String userId;
String mUsername;
String email;
int age;
int stars;
int badReputation;
String gender;
int birthYear;
int birthMonth;
int birthDay;
public User()
{
}
public User(String userId,String mUsername,String email) {
mDatabase = FirebaseDatabase.getInstance().getReference();
this.userId = userId;
this.mUsername = mUsername;
age = getAge();
stars = 0;
this.email=email;
badReputation = 0;
gender = "";
}
Кроме того, у меня есть другой класс, в котором dataSnapshot.getValue класса User. И это работает отлично, что с этим делать?? Вот код:
public void retrieveUser()
{
//create datarefence of only 1 user namely the current user
DatabaseReference specificCreatorRef =mDatabase.child("users").child(user.getUid());
specificCreatorRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
//Now retrieving the current user and putting it in object mUser
mUser = dataSnapshot.getValue(User.class);
Log.w(TAGESS, "Print STARS of current mUSer: " + mUser.getStars());
creatorGender =mUser.getGender();
}
@Override
public void onCancelled(DatabaseError databaseError) {
// Getting Post failed, log a message
Log.w(TAG, "loadPost:onCancelled", databaseError.toException());
// ...
}
});
}
Итак, этот последний код работает идеально, так почему же работает он, а не DataSnapshot.getValue(Game.class)? Спасибо!