RegistrationActivity.java
btnRegister.setOnClickListener(new View.OnClickListener() {
Boolean flag = false;
@Override
public void onClick(View view) {
Firebase ref = new Firebase(Config.FIREBASE_USERS_URL);
String userName = edtRegistrationUsername.getText().toString().trim();
final User user = new User();
user.setUserName(userName,RegistrationActivity.this);
ref.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
for (DataSnapshot postSnapshot : snapshot.getChildren()) {
//Getting the data from snapshot
User user1 = postSnapshot.getValue(User.class);
if(user1.getUserName().equals(user.getUserName())){
Toast.makeText(RegistrationActivity.this,"That username is already taken",Toast.LENGTH_LONG);
flag = false;
}else{
flag = true;
}
}
}
@Override
public void onCancelled(FirebaseError firebaseError) {
System.out.println("The read failed: " + firebaseError.getMessage());
}
});
if(flag == true){
ref.push().setValue(user);
}
}
});
如果用户名存在,我想检查firebase数据库,否则在firebase中添加用户名。
当我输入用户名并单击注册时,程序崩溃并显示错误:
Task exception on worker thread: java.lang.IncompatibleClassChangeError: The method 'java.io.File android.support.v4.content.ContextCompat.getNoBackupFilesDir(android.content.Context)' was expected to be of type virtual but instead was found to be of type direct (declaration of 'com.google.firebase.iid.zzg'
我希望有人可以帮我解决问题。谢谢!