显示空我想读的火力点数据库中的数据,但每次DataSnapshot是给空值,我是能够更新数据,但无法读取它。DataSnapshot数据在安卓
任何一个可以帮助我
private void showData(DataSnapshot dataSnapshot) {
for(DataSnapshot ds : dataSnapshot.getChildren()){
UserInformation uInfo = new UserInformation();
uInfo.setName(ds.child(userID).getValue(UserInformation.class).getName()); //set the name
uInfo.setEmail(ds.child(userID).getValue(UserInformation.class).getEmail()); //set the email
uInfo.setPhone_num(ds.child(userID).getValue(UserInformation.class).getPhone_num()); //set the phone_num
//display all the information
Log.d(TAG, "showData: name: " + uInfo.getName());
Log.d(TAG, "showData: email: " + uInfo.getEmail());
Log.d(TAG, "showData: phone_num: " + uInfo.getPhone_num());
Toast.makeText(this,uInfo.getName().toString(),Toast.LENGTH_SHORT).show();
ArrayList<String> array = new ArrayList<>();
array.add(uInfo.getName());
array.add(uInfo.getEmail());
array.add(uInfo.getPhone_num());
ArrayAdapter adapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1,array);
mListView.setAdapter(adapter);
}
}
我调用此函数从
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.
try {
showData(dataSnapshot);
}catch (Exception e)
{
toastMessage("datasnapshow Exception"+e);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
这会给我空例外。我坚持这个问题,任何人都可以帮助我。数据库结构:
{
myfirebase284
m0p7r9ryj5Mr22NVWUt1DcYTjqG2
email: "[email protected]"
name: "pema"
phone_num: 9990480514
}
你可以发布你的数据库结构的图片吗? – wnieves19
你可以请使用json文件吗?或者取而代之,一张照片? –
任何好的教程,展示如何从firebased读取数据@Alex Mamo –