DataSnapshot:尝试在空对象引用上调用虚拟方法'java.lang.String java.lang.Object.toString()'

时间:2019-02-28 08:26:20

标签: java android firebase

此行中发生错误。

String value = dataSnapshot.getValue().toString();

其周围的代码为:

SharedPreferences sharedPreferences = getActivity().getSharedPreferences("email", Context.MODE_PRIVATE);
stUid = sharedPreferences.getString("uid", "");
stEmail = sharedPreferences.getString("email", "");

pbLogin = (ProgressBar)v.findViewById(R.id.pbLogin);

FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference myRef = database.getReference();

myRef.child("users").child(stUid).addListenerForSingleValueEvent(new ValueEventListener() {
    @Override
    public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
        // This method is called once with the initial value and ag-ain
        // whenever data at this location is updated.
        String value = dataSnapshot.getValue().toString();
        String stPhoto = dataSnapshot.child("photo").getValue().toString();

这是我的数据库表。

enter image description here

0 个答案:

没有答案