我的教程 “https://firebase.google.com/docs/database/android/start/?hl=ko”的火力地堡实时数据库火力地堡实时databae不工作,SETVALUE
做出样品但是在我看不到任何数据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());
}
});
这是我的代码。
我的错是什么?
我没有立即看到什么是你的代码错误。你在logcat输出中看到任何消息吗? –
在[这个问题](https://stackoverflow.com/questions/46742714/firebase-realtimedatabase-is-not-working-now)看到完全相同的代码后,我不知道你是否没有网络连接。这是我可以很快想到的唯一情况,那么onDataChange()和onCancelled()都不会被调用。 –