gpt4 book ai didi

java - 无法在child()错误中为参数“pathString”传递null

转载 作者:行者123 更新时间:2023-12-01 17:06:31 25 4
gpt4 key购买 nike

下一行有错误。它说不能为参数传递null

'pathString' in child() 
UsersRef = FirebaseDatabase.getInstance().getReference().child("Users").child(currentUserID);


import com.google.firebase.database.FirebaseDatabase;
import java.util.HashMap;

public class SetupActivity extends AppCompatActivity {

private EditText UserName, FullName, CountryName;
private Button SaveInformationButton;
private CircleImageView ProfileImage;
private FirebaseAuth mAuth;
private DatabaseReference UsersRef;
String currentUserID;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_setup);

mAuth = FirebaseAuth.getInstance();
UsersRef = FirebaseDatabase.getInstance().getReference().child("Users").child(currentUserID);
currentUserID = mAuth.getCurrentUser().getUid();

UserName = (EditText) findViewById(R.id.txt_email);
FullName = (EditText) findViewById(R.id.txt_fullname);
CountryName = (EditText) findViewById(R.id.txt_country);
SaveInformationButton = (Button) findViewById(R.id.button);
ProfileImage = (CircleImageView) findViewById(R.id.circleImageView);

SaveInformationButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SaveAccountSetupInformation();
}
});
}

private void SaveAccountSetupInformation() {

String username = UserName.getText().toString();
String fullName = FullName.getText().toString();
String country = CountryName.getText().toString();

if(TextUtils.isEmpty(username)){
Toast.makeText(this, "Please write your username", Toast.LENGTH_SHORT).show();
}

if(TextUtils.isEmpty(fullName)){
Toast.makeText(this, "Please write your fullname", Toast.LENGTH_SHORT).show();
}

if(TextUtils.isEmpty(country)){
Toast.makeText(this, "Please confirm your country", Toast.LENGTH_SHORT).show();
}
else{
HashMap userMap = new HashMap();
userMap.put("username", username);
userMap.put("fullName", fullName);
userMap.put("country", country);
userMap.put("status", "Hey there, I am using this app");
userMap.put("gender", "none");
userMap.put("dob", "none");
userMap.put("relationshipstatus", "none");
UsersRef.updateChildren(userMap).addOnCompleteListener(new OnCompleteListener() {
@Override
public void onComplete(@NonNull Task task) {
if(task.isSuccessful()){

SendUserToHomeActivity();
Toast.makeText(SetupActivity.this, "Your account is created successfully", Toast.LENGTH_SHORT).show();
}
else{
String message = task.getException().getMessage();
Toast.makeText(SetupActivity.this, "Error Occurred"+ message, Toast.LENGTH_SHORT).show();
}
}
});
}
}

private void SendUserToHomeActivity(){
Intent homeIntent = new Intent(SetupActivity.this, HomeActivity.class);
homeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(homeIntent);
finish();
}
}

最佳答案

您首先定义数据库引用。然后定义用户标识。因此,用户ID为null,您会收到此错误。更改currentUserID的位置:

mAuth = FirebaseAuth.getInstance();
currentUserID = mAuth.getCurrentUser().getUid();
UsersRef = FirebaseDatabase.getInstance().getReference().child("Users").child(currentUserID);

关于java - 无法在child()错误中为参数“pathString”传递null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61461071/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com