我是通过教程制作的 ' https://firebase.google.com/docs/database/android/start/?hl=ko'用于Firebase实时数据库
但我在onDataChanged
' EventValueListner'
你能解释一下为什么吗?
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference myRef = database.getReference("message");
myRef.setValue("Hello, World!");
// Read from the database
myRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
// This method is called once with the initial value and again
// whenever data at this location is updated.
String value = dataSnapshot.getValue(String.class);
Log.d("TAG", "Value is: " + value);
}
@Override
public void onCancelled(DatabaseError error) {
// Failed to read value
Log.w("TAG", "Failed to read value.", error.toException());
}
});
这是我的代码。
我的错是什么?
答案 0 :(得分:0)
此示例将在firebase db中插入新用户数据。
FirebaseDatabase database;
DatabaseReference usersTable;
database = FirebaseDatabase.getInstance();
usersTable = database.getReference("Users");
/*we work here */
usersTable.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
progressDialog.dismiss();
if (dataSnapshot.child(phoneEditText.getText().toString()).exists()) {
Toast.makeText(SignUp.this, "Number already register", Toast.LENGTH_SHORT).show();
}else{
Users users = new Users(nameEditText.getText().toString(),passwordEditTex.getText().toString(),phoneEditText.getText().toString());
usersTable.child(phoneEditText.getText().toString()).setValue(users);
Toast.makeText(SignUp.this, "Signup Sucessfully", Toast.LENGTH_SHORT).show();
finish();
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
希望这会对你有所帮助