我想编辑" user_mobile"和" user_blood"。
我试过这段代码。
mAuth = FirebaseAuth.getInstance();
String online_user_id = mAuth.getCurrentUser().getUid();
getUserDataReference = FirebaseDatabase.getInstance().getReference().child("Users").child(online_user_id);
getUserDataReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
//dataSnapshot.get
String name = dataSnapshot.child("user_name").getValue().toString();
String status = dataSnapshot.child("user_status").getValue().toString();
String image = dataSnapshot.child("user_image").getValue().toString();
mobile = dataSnapshot.child("user_mobile").getValue().toString();
String thumb_image = dataSnapshot.child("user_thumb_image").getValue().toString();
settingDisplayName.setText(name);
settingDisplayStatus.setText(status);
if (!image.equals("default_profile"))
{
Picasso.with(SettingActivity.this).load(image).placeholder(R.drawable.default_profile).into(settingsDisplayImage);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
以下是错误。
FATAL EXCEPTION: main
Process: com.logictex.bloodbank, PID: 2486
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.Object.toString()' on a null object reference
at com.logictex.bloodbank.SettingActivity$1.onDataChange(SettingActivity.java:77)
at com.google.android.gms.internal.zzbmz.zza(Unknown Source)
at com.google.android.gms.internal.zzbnz.zzYj(Unknown Source)
at com.google.android.gms.internal.zzboc$1.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
答案 0 :(得分:0)
DatabaseReference xyz=
FirebaseDatabase.getInstance().getReference().child("Users").child(online_user_id).child("user_mobile");
xyz.setValue("set_desired vaule");
对use_blood做同样的事情
答案 1 :(得分:0)
可能是您的路径document.getElementById("demo1").innerHTML
= parseInt(xhttp.getResponseHeader("Content-Length"));
不存在。
FirebaseDatabase.getInstance().getReference().child("Users").child(online_user_id);
答案 2 :(得分:0)
要解决此问题,您需要使用以下代码:
DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
DatabaseReference user_mobileRef = rootRef.child("Users").child(user_blood).child(online_user_id).child("user_mobile");
user_mobileRef.setValue("YourNewValue");
DatabaseReference user_bloodRef = rootRef.child("Users").child(user_blood).child(online_user_id).child("user_blood");
user_bloodRef.setValue("YourNewValue");