我试图用Firebase做一个简单的聊天项目但是在唱歌的方法中我有一个FirebaseException错误:当我尝试使用dataSnapshot实例化currentUser时,无法反弹到键入。 这是方法:
public void signIn(String email, String password) {
dataReference.authWithPassword(email, password, new Firebase.AuthResultHandler() {
@Override
public void onAuthenticated(AuthData authData) {
myUserReference = helper.getMyUserReference();
myUserReference.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
User currentUser = dataSnapshot.getValue(User.class);
if (currentUser == null) {
String email = helper.getAuthUserEmail();
if (email != null) {
currentUser = new User();
myUserReference.setValue(currentUser);
}
}
helper.changeUserContectionStatus(User.ONLINE);
postEvent(LoginEvent.ON_SING_IN_SUCCESS);
}
@Override
public void onCancelled(FirebaseError firebaseError) {
}
});
}
@Override
public void onAuthenticationError(FirebaseError firebaseError) {
postEvent(LoginEvent.ON_SING_IN_ERROR,firebaseError.getMessage() );
}
});
}
这是POJO:
public class User {
String email;
boolean online;
Map<String,Boolean> contacs;
public static final boolean ONLINE = true;
public static final boolean OFFLINE = false;
public User() {
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public boolean isOnline() {
return online;
}
public void setOnline(boolean online) {
this.online = online;
}
public Map<String, Boolean> getContacs() {
return contacs;
}
public void setContacs(Map<String, Boolean> contacs) {
this.contacs = contacs;
}
@Override
public boolean equals(Object object){
boolean equals = false;
if (object instanceof User) {
User user = (User)object;
equals = this.email.equals(user.getEmail());
}
return equals;
}
}