【发布时间】:2017-10-14 11:52:45
【问题描述】:
我按教程制作了示例 '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());
}
});
这是我的代码。
我的错是什么?
【问题讨论】:
-
我没有立即看出您的代码有什么问题。您在 logcat 输出中看到任何消息吗?
-
在this question看到完全相同的代码后,我想知道你是不是根本没有网络连接。这是我能很快想到的唯一情况,那么
onDataChange()和onCancelled()都不会被调用。
标签: android firebase-realtime-database