Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
138 views
in Technique[技术] by (71.8m points)

android - Data storing in wrong field in firebase realtime database

enter code here I have a registration form in android application where user can enter their details. And i try to store data into firebase, the data are storing but the problem is in phone number age will store, in age field name will store. How to solve this issue? Please help!

Helperclass

public class UserHelperClass {

String fullName, city, age, disease, gender, bloodGroup, password, phoneNumber;

 public UserHelperClass() {
}

public UserHelperClass(String fullName, String city, String age, String disease, String gender, String bloodGroup, String password, String phoneNumber) {
    this.fullName = fullName;
    this.city = city;
    this.age = age;
    this.disease = disease;
    this.gender = gender;
    this.bloodGroup = bloodGroup;
    this.password = password;
    this.phoneNumber = phoneNumber;
}

public String getFullName() {
    return fullName;
}

public void setFullName(String fullName) {
    this.fullName = fullName;
}

public String getCity() {
    return city;
}

public void setCity(String city) {
    this.city = city;
}

public String getAge() {
    return age;
}

public void setAge(String age) {
    this.age = age;
}

public String getDisease() {
    return disease;
}

public void setDisease(String disease) {
    this.disease = disease;
}

public String getGender() {
    return gender;
}

public void setGender(String gender) {
    this.gender = gender;
}

public String getBloodGroup() {
    return bloodGroup;
}

public void setBloodGroup(String bloodGroup) {
    this.bloodGroup = bloodGroup;
}

public String getPassword() {
    return password;
}

public void setPassword(String password) {
    this.password = password;
}

public String getPhoneNumber() {
    return phoneNumber;
}

public void setPhoneNumber(String phoneNumber) {
    this.phoneNumber = phoneNumber;
}

}

data storing to firebase code

    rootNode=FirebaseDatabase.getInstance();
    reference=rootNode.getReference("Users");

    UserHelperClass helperClass=new UserHelperClass(fullName,city,age,phoneNumber,bloodGroup,age,disease,password);

    reference.child(phoneNumber).setValue(helperClass);

geting data from another activity

phoneNumber = getIntent().getStringExtra("keynumber");
    fullName = getIntent().getStringExtra("keyname");
    city = getIntent().getStringExtra("keycity");
    age = getIntent().getStringExtra("keyage");
    disease = getIntent().getStringExtra("keydisease");
    bloodGroup = getIntent().getStringExtra("keybloodgroup");
    gender = getIntent().getStringExtra("keygender");
    password = getIntent().getStringExtra("keypassword");

pass data to another activity

public class RegisterActivity extends AppCompatActivity {

private AutoCompleteTextView dropDownText;
TextView titletext;
TextView chooegender;
TextView selectage;
TextInputLayout fullname, city, number, disease, password, bloodgroup;
RadioGroup radioGroup;
RadioButton selectedGender, radio1, radio2, radio3;
DatePicker datePicker;
CountryCodePicker countryCodePicker;
Button registerbtn;



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


    dropDownText = findViewById(R.id.dropdown_text);
    titletext = findViewById(R.id.title_text);
    chooegender = findViewById(R.id.choose_gender);
    selectage = findViewById(R.id.select_age);
    fullname = findViewById(R.id.name);
    city = findViewById(R.id.city);
    number = findViewById(R.id.number);
    countryCodePicker = findViewById(R.id.country_code_picker);
    disease = findViewById(R.id.disease);
    bloodgroup = findViewById(R.id.bloodgroup);
    password = findViewById(R.id.password);

    radio1 = findViewById(R.id.radioButton1);
    radio2 = findViewById(R.id.radioButton2);
    radio3 = findViewById(R.id.radioButton3);

    radioGroup = findViewById(R.id.radiogroup);
    datePicker = findViewById(R.id.age_picker);
    selectedGender = findViewById(radioGroup.getCheckedRadioButtonId());
    registerbtn = findViewById(R.id.register);



    String[] item = new String[]{
            "A+Ve",
            "A-Ve",
            "B+Ve",
            "B-Ve",
            "AB+Ve",
            "AB-Ve",
            "O+Ve",
            "O-Ve"

    };
    ArrayAdapter<String> adapter = new ArrayAdapter<>(
            RegisterActivity.this,
            R.layout.dropdown_item,
            item
    );
    dropDownText.setAdapter(adapter);
}

public void callotpverificationscreen(View view) {
    if (!validateFullname() | !validateCity() | !validateDisease() | !validateNumber() | !validatePassword() | !validateGender() | !validateAge())
        return;

    selectedGender = findViewById(radioGroup.getCheckedRadioButtonId());
    String _gender = selectedGender.getText().toString().trim();

    int day = datePicker.getDayOfMonth();
    int month = datePicker.getMonth();
    int year = datePicker.getYear();

    String Age = day + "/" + month + "/" + year;
    String FullName = fullname.getEditText().getText().toString();
    String City = city.getEditText().getText().toString().trim();
    String Disease = disease.getEditText().getText().toString().trim();
    String Blood_group = bloodgroup.getEditText().getText().toString().trim();
    String code = countryCodePicker.getSelectedCountryCodeWithPlus();
    String Number = number.getEditText().getText().toString().trim();
    String CompletePhoneNumber = "+" + countryCodePicker.getFullNumber() + Number;
    String Password = password.getEditText().getText().toString().trim();


    Intent intent = new Intent(getApplicationContext(), OTP_verification.class);
    intent.putExtra("keyname", FullName);
    intent.putExtra("keycity", City);
    intent.putExtra("keyage", Age);
    intent.putExtra("keydisease", Disease);
    intent.putExtra("keybloodgroup", Blood_group);
    intent.putExtra("keynumber", CompletePhoneNumber);
    intent.putExtra("keypassword", Password);
    intent.putExtra("keygender", _gender);
    startActivity(intent);


}

Firebase database image(https://i.stack.imgur.com/YYoYt.jpg)

question from:https://stackoverflow.com/questions/65649991/data-storing-in-wrong-field-in-firebase-realtime-database

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You haven't followed the correct order like UserHelperClass: You should follow this format:

fullName, city, age, disease, gender, bloodGroup, password, phoneNumber

But you have used wrong order when calling class. Use this format

    UserHelperClass helperClass=new UserHelperClass(fullName, city, age, disease, gender, bloodGroup, password, phoneNumber);

In-spite of this:

    UserHelperClass helperClass=new UserHelperClass(fullName,city,age,phoneNumber,bloodGroup,age,disease,password);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...