My data is not the same as user input and database
My data is not the same as user input and database
My data is not the same as user input and database. Data between age and gender is exchanged. How can this happen? What coding should I paste here?
Register Button:-
RegisterButton.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View v)
SaveAccountInformation();
);
SaveAccountInformation Method:-
private void SaveAccountInformation()
{
String usertype = RegisterUserType.getSelectedItem().toString();
String firstname = RegisterFirstName.getText().toString();
String lastname = RegisterLastName.getText().toString();
String gender = RegisterUserGender.getSelectedItem().toString();
String age = RegisterAge.getText().toString();
String phonenum = RegisterPhoneNumber.getText().toString();
String userid = databaseUser.push().getKey();
User user = new User(userid, usertype, firstname, lastname, age, gender, phonenum);
databaseUser.child(userid).setValue(user)
.addOnSuccessListener(new OnSuccessListener<Void>()
@Override
public void onSuccess(Void aVoid)
Toast.makeText(RegistrationActivity.this, "Registration has been successful.", Toast.LENGTH_SHORT).show();
loadingBar.dismiss();
)
.addOnFailureListener(new OnFailureListener()
@Override
public void onFailure(@NonNull Exception e)
Toast.makeText(RegistrationActivity.this, "Error occurred. Please try again.", Toast.LENGTH_SHORT).show();
loadingBar.dismiss();
);
Constructor coding:-
public User(String userId, String userType, String userFirstName, String userLastName, String userGender, String userAge, String userContactNumber)
this.userId = userId;
this.userType = userType;
this.userFirstName = userFirstName;
this.userLastName = userLastName;
this.userGender = userGender;
this.userAge = userAge;
this.userContactNumber = userContactNumber;
No I didnt load them through the database. Then what should I do? I dont get it clear @GabeSechan
– Adda
Aug 31 at 3:50
All the input is in the String type...
– Adda
Aug 31 at 3:53
Check your
User
model class if your age and gender is in the right assigning place. E.g. this.gender = gender
.– Tepits
Aug 31 at 4:07
User
this.gender = gender
Just show us the actual constructor, and the database calls. We don't need to see all the getters. It's hard to tell, but the call to the constructor you showed before listed age before gender, and it looks like in your class you have gender before age.
– David Conrad
Aug 31 at 5:25
2 Answers
2
My error on this coding line: -
User user = new User(userid, usertype, firstname, lastname, gender, age, phonenum);
GREAT.... lololol
– Ümañg ßürmån
Aug 31 at 5:38
Your constructor must be the same as the database range your class User
I already edit my question. As you can see in the image, the constructor same as in the database, right? :D
– Adda
Aug 31 at 5:09
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Did you swap the parameters in the constructor? Or did you load them from the db in the wrong order? As a side note, if you stored the variable as an integer in the db rather than a string it would likely have become a syntax error that's much easier to find.
– Gabe Sechan
Aug 31 at 3:47