0
我在Firebase中設置了一個子項的值,但是當我從Firebase獲取值時,該值爲null。我不明白爲什麼。Android - 從Firebase返回null的getValue返回null
database.child("User").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
int depositInteger = 0;
try {
depositInteger = Integer.parseInt(depositText.getText().toString().trim());
} catch (NumberFormatException e) {
if (depositText.equals("")) {
Toast.makeText(getActivity(), "Failed", Toast.LENGTH_SHORT).show();
}
}
database.child(user.getDisplayName()).child("deposit").setValue(depositInteger);
Long previousDeposit = dataSnapshot.child("User").child(user.getDisplayName()).child("deposit").getValue(Long.class);
System.out.println("VAAAALUE: " + previousDeposit);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
從這裏引用https://stackoverflow.com/questions/44494430/retrieve-user-data-from-firebase-database/44497238#44497238 –