Не удалось передать ноль для аргумента pathString в ошибке child () - PullRequest
0 голосов
/ 27 апреля 2020

Ошибка в строке ниже. Это говорит, что не может передать нуль для аргумента

'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();
     }
}

1 Ответ

0 голосов
/ 29 апреля 2020

Сначала вы определяете ссылку на базу данных. Затем вы определяете идентификатор пользователя. Таким образом, идентификатор пользователя равен нулю, и вы получите эту ошибку. Изменить место currentUserID:

mAuth = FirebaseAuth.getInstance();
currentUserID = mAuth.getCurrentUser().getUid();
UsersRef = FirebaseDatabase.getInstance().getReference().child("Users").child(currentUserID);
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...