This question already has answers here:
Firebase: setting additional user properties
(2 answers)
Closed 3 years ago.
I want to add some extra flied to user when he signup, the method does not let me do it.
I want to add username, city, phone, as extra parameter
public class SignupActivity extends AppCompatActivity {
private EditText inputEmail, inputPassword,inputUserName,inputCity,inputPhone_Num;
private Button btnSignIn, btnSignUp, btnResetPassword;
private ProgressBar progressBar;
private FirebaseAuth auth;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_signup);
//Get Firebase auth instance
auth = FirebaseAuth.getInstance();
btnSignIn = (Button) findViewById(R.id.sign_in_button);
btnSignUp = (Button) findViewById(R.id.sign_up_button);
inputUserName = (EditText) findViewById(R.id.username);
inputCity = (EditText) findViewById(R.id.city);
inputPhone_Num = (EditText) findViewById(R.id.phone);
inputEmail = (EditText) findViewById(R.id.email);
inputPassword = (EditText) findViewById(R.id.password);
progressBar = (ProgressBar) findViewById(R.id.progressBar);
btnResetPassword = (Button) findViewById(R.id.btn_reset_password);
btnResetPassword.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(SignupActivity.this, ResetPasswordActivity.class));
}
});
btnSignIn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
finish();
}
});
btnSignUp.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String username = inputUserName.getText().toString().trim();
String city = inputCity.getText().toString().trim();
String phone = inputPhone_Num.getText().toString().trim();
String email = inputEmail.getText().toString().trim();
String password = inputPassword.getText().toString().trim();
if (TextUtils.isEmpty(username)) {
Toast.makeText(getApplicationContext(), "Enter username address!", Toast.LENGTH_SHORT).show();
return;
}
if (TextUtils.isEmpty(city)) {
Toast.makeText(getApplicationContext(), "Enter city address!", Toast.LENGTH_SHORT).show();
return;
}
if (TextUtils.isEmpty(phone)) {
Toast.makeText(getApplicationContext(), "Enter phone numer address!", Toast.LENGTH_SHORT).show();
return;
}
if (TextUtils.isEmpty(email)) {
Toast.makeText(getApplicationContext(), "Enter email address!", Toast.LENGTH_SHORT).show();
return;
}
if (TextUtils.isEmpty(password)) {
Toast.makeText(getApplicationContext(), "Enter password!", Toast.LENGTH_SHORT).show();
return;
}
if (password.length() < 6) {
Toast.makeText(getApplicationContext(), "Password too short, enter minimum 6 characters!", Toast.LENGTH_SHORT).show();
return;
}
progressBar.setVisibility(View.VISIBLE);
here I want to add username, city, phone, as extra parameter
auth.createUserWithEmailAndPassword**(email, password)**
.addOnCompleteListener(SignupActivity.this, new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
Toast.makeText(SignupActivity.this, "createUserWithEmail:onComplete:" + task.isSuccessful(), Toast.LENGTH_SHORT).show();
progressBar.setVisibility(View.GONE);
// If sign in fails, display a message to the user. If sign in succeeds
// the auth state listener will be notified and logic to handle the
// signed in user can be handled in the listener.
if (!task.isSuccessful()) {
Toast.makeText(SignupActivity.this, "Authentication failed." + task.getException(),
Toast.LENGTH_SHORT).show();
} else {
startActivity(new Intent(SignupActivity.this, ProfileActivity.class));
finish();
}
}
});
}
});
}
#Override
protected void onResume() {
super.onResume();
progressBar.setVisibility(View.GONE);
}
}
If you want to add username/City/address then you need to use your own implementation. The method createuserwithEmailAndPassword adds a user to the Firebase authentication console. Also it will give you a unique ID for each user. Please check the following:
https://firebase.google.com/docs/auth/android/manage-users
If you want to add those extra info, then it is better to use firebase database with firebase authentication.
Related
I am new to android so there is some problem when i run the code to register or login with firebase authentication i can run the code but when i execute the signup function after pressing the register button it takes a lot time to register 1 account.
`
public class RegisterActivity extends AppCompatActivity implements View.OnClickListener {
private FirebaseAuth mAuth;
private Button btn_register;
private EditText et_name, et_age, et_email, et_password;
private ProgressBar ProgressBar;
private TextView name_project;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
mAuth = FirebaseAuth.getInstance();
name_project = (TextView) findViewById(R.id.name_project);
name_project.setOnClickListener(this);
btn_register = (Button) findViewById(R.id.btn_register);
btn_register.setOnClickListener(this);
et_name = (EditText) findViewById(R.id.et_name);
et_age = (EditText) findViewById(R.id.et_age);
et_email = (EditText) findViewById(R.id.et_email);
et_password = (EditText) findViewById(R.id.et_password);
ProgressBar = (ProgressBar) findViewById(R.id.progressBar);
}
#Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.name_project:
startActivity(new Intent(this, MainActivity.class));
break;
case R.id.btn_register:
registerUser();
break;
}
}
private void registerUser() {
String email = et_email.getText().toString().trim();
String password = et_password.getText().toString().trim();
String name = et_name.getText().toString().trim();
String age = et_age.getText().toString().trim();
if (name.isEmpty()) {
et_name.setError("Please enter your full name");
et_name.requestFocus();
return;
}
if (age.isEmpty()) {
et_age.setError("Please enter your age");
et_age.requestFocus();
return;
}
if (email.isEmpty()) {
et_email.setError("Please enter your email");
et_email.requestFocus();
return;
}
if (password.isEmpty()) {
et_password.setError("Please enter your password");
et_password.requestFocus();
return;
}
if (!Patterns.EMAIL_ADDRESS.matcher(email).matches()) {
et_email.setError("Please enter valid email");
et_email.requestFocus();
return;
}
if (password.length() < 6) {
et_password.setError("The length of password should be more than 6 letters");
et_password.requestFocus();
return;
}
ProgressBar.setVisibility(View.VISIBLE);
mAuth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
Intent intent = new Intent(RegisterActivity.this, MainActivity.class);
startActivity(intent);
finish();
Toast.makeText(RegisterActivity.this, "Registered successfully", Toast.LENGTH_SHORT).show();
ProgressBar.setVisibility(View.GONE);
} else {
Toast.makeText(RegisterActivity.this, "Registered fail", Toast.LENGTH_SHORT).show();
ProgressBar.setVisibility(View.GONE);
}
}
});
}
}
enter image description here`
I have tried many methods but registration takes a long time.
Please make sure you have enabled the Email/Password provider in the Authentification tab on the Firebase console.
I am developing an app on android studio and need to redirect clients and personal trainers to two different activities based on their role. Personal Trainers need to be directed to PTNoticeboardActivity and clients to NoticeboardActivity. Any suggestion on how to do this, here is my login code:
public class MainActivity extends AppCompatActivity {
private FirebaseAuth firebaseAuth;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
firebaseAuth = FirebaseAuth.getInstance();
}
public void loginUser(View View){
String email = ((EditText) findViewById(R.id.editText_Log_email)).getText().toString();
String password = ((EditText) findViewById(R.id.editText_Log_password)).getText().toString();
if(TextUtils.isEmpty(email)){
Toast.makeText(this, "Please enter email", Toast.LENGTH_LONG).show();
return;
}
if (TextUtils.isEmpty(password)){
Toast.makeText(this, "Please Enter Password", Toast.LENGTH_LONG).show();
return;
}
firebaseAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener(MainActivity.this, new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if(task.isSuccessful()){
Toast.makeText(MainActivity.this, "Login Successful", Toast.LENGTH_LONG).show();
// startActivity(new Intent(getApplicationContext(), NoticeBoardActivity.class));
// finish();
} else {
Toast.makeText(MainActivity.this, "Login Unsuccessful", Toast.LENGTH_LONG).show();
}
}
});
}
}
Here is my register activity code below:
public class RegisterActivity extends AppCompatActivity {
EditText txt_fullname, txt_email, txt_mobilenumber, txt_repassword,
txt_password;
Button btn_register;
RadioButton radioJobClient, radioJobPT;
DatabaseReference databaseReference;
FirebaseDatabase firebaseDatabase;
String job ="";
FirebaseAuth firebaseAuth;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
txt_fullname = (EditText) findViewById(R.id.editText_fullname);
txt_email = (EditText) findViewById(R.id.editText_UserEmail);
txt_password = (EditText) findViewById(R.id.editText_Password);
txt_repassword = (EditText) findViewById(R.id.editText_rePassword);
txt_mobilenumber = (EditText) findViewById(R.id.mobilenumber);
btn_register = (Button) findViewById(R.id.button_reg);
radioJobClient = (RadioButton) findViewById(R.id.radio_Client);
radioJobPT = (RadioButton) findViewById(R.id.radio_PersonalTrainer);
databaseReference = FirebaseDatabase.getInstance().getReference("User");
// new code
firebaseAuth = FirebaseAuth.getInstance();
btn_register.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final String fullname = txt_fullname.getText().toString();
final String email = txt_email.getText().toString();
final String mobilenumber = txt_mobilenumber.getText().toString();
final String password = txt_password.getText().toString();
final String rePassword = txt_repassword.getText().toString();
if (radioJobClient.isChecked()){
job = "Client";
}
if (radioJobPT.isChecked()){
job = "PT";
}
if (TextUtils.isEmpty(email)){
Toast.makeText(RegisterActivity.this, "Please enter Email", Toast.LENGTH_LONG).show();
}
if (TextUtils.isEmpty(fullname)){
Toast.makeText(RegisterActivity.this, "Please enter fullname", Toast.LENGTH_LONG).show();
}
if (TextUtils.isEmpty(password)){
Toast.makeText(RegisterActivity.this, "Please enter password", Toast.LENGTH_LONG).show();
}
firebaseAuth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(RegisterActivity.this, new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
User user = new User(
fullname,
email,
mobilenumber,
password,
job
);
FirebaseDatabase.getInstance().getReference("User")
.child(FirebaseAuth.getInstance().getCurrentUser().getUid())
.setValue(user).addOnCompleteListener(new OnCompleteListener<Void>() {
#Override
public void onComplete(#NonNull Task<Void> task) {
Toast.makeText(RegisterActivity.this, "Registration Complete", Toast.LENGTH_SHORT).show();
startActivity(new Intent(getApplicationContext(),MainActivity.class));
}
});
} else {
Toast.makeText(RegisterActivity.this, "Registration Unsuccessful", Toast.LENGTH_LONG).show();
}
// ...
}
});
}
});
}
public void goLogin (View view){
startActivity(new Intent(RegisterActivity.this, MainActivity.class));
}
}
Database structure:
This is the most efficient way to do it:
When your user has created an account, create a child node in the firebase database as role with value as per the user. [could be client or personal trainer]
Then when your activity starts, fetch the value from the database like this:
First of all add a LOGIN BUTTON toyour login activity. When user presses that then only the login thing will take place.
Here is your modified MainActivity.java:
public class MainActivity extends AppCompatActivity {
private FirebaseAuth firebaseAuth;
String userRole;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
firebaseAuth = FirebaseAuth.getInstance();
btnLogin = findViewById(R.id.btn_login_resource);
btnLogin.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String email = ((EditText) findViewById(R.id.editText_Log_email)).getText().toString();
String password = ((EditText) findViewById(R.id.editText_Log_password)).getText().toString();
if(TextUtils.isEmpty(email)){
Toast.makeText(this, "Please enter email", Toast.LENGTH_LONG).show();
return;
}
else if (TextUtils.isEmpty(password)){
Toast.makeText(this, "Please Enter Password", Toast.LENGTH_LONG).show();
return;
}
else{
firebaseAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener(MainActivity.this, new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if(task.isSuccessful()){
Toast.makeText(MainActivity.this, "Login Successful", Toast.LENGTH_LONG).show();
jobRef = FirebaseDatabase.getInstance().getReference().child("User").child(pAuth.getCurrentUser().getUid()).child("job");
jobRef.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot dataSnapshot) {
try {
userRole = dataSnapshot.getValue().toString();
if(userRole.equals("Client")){
startActivity(new Intent(MainActivity.this, NoticeboardActivity.class);
}
else {
startActivity(new Intent(MainActivity.this, PTNoticeboardActivity.class);
}
}catch (Throwable e){
Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_SHORT).show();
}
}
#Override
public void onCancelled(#NonNull DatabaseError databaseError) {
Toast.makeText(getApplicationContext(), databaseError.toString(), Toast.LENGTH_SHORT).show();
}
});
} else {
Toast.makeText(MainActivity.this, "Login Unsuccessful", Toast.LENGTH_LONG).show();
}
}
});
}
}
}
});
.
Now one thing to care about is that anyone can reverse-engineer this code and illegally can get access to the data. So make sure the data in each activity is hosted in Firebase and you have set the appropriate firebase rules. If you want me to elaborate please let me know in the comments down below.
Firebase stores the email and password.
I need to add username to registration.
I also need to authenticate (Login) Users with Username/Password NOT Email/Password.
Registration should have username, email and password...
While Login should be with username and password.
RegisterActivity.java
public class RegisterActivity extends AppCompatActivity {
private EditText inputEmail, inputPassword;
private Button btnSignUp;
private ProgressBar progressBar;
private FirebaseAuth auth;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
auth = FirebaseAuth.getInstance();
btnSignUp = (Button) findViewById(R.id.sign_up_button);
inputEmail = (EditText) findViewById(R.id.email);
inputPassword = (EditText) findViewById(R.id.password);
progressBar = (ProgressBar) findViewById(R.id.progressBar);
btnSignUp.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String email = inputEmail.getText().toString().trim();
String password = inputPassword.getText().toString().trim();
if (TextUtils.isEmpty(email)) {
Toast.makeText(getApplicationContext(), "Enter email address!", Toast.LENGTH_SHORT).show();
return;
}
if (TextUtils.isEmpty(password)) {
Toast.makeText(getApplicationContext(), "Enter password!", Toast.LENGTH_SHORT).show();
return;
}
if (password.length() < 6) {
Toast.makeText(getApplicationContext(), "Password too short, enter minimum 6 characters!", Toast.LENGTH_SHORT).show();
return;
}
progressBar.setVisibility(View.VISIBLE);
//create user
auth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(RegisterActivity.this, new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
progressBar.setVisibility(View.GONE);
// If sign in fails, display a message to the user. If sign in succeeds
// the auth state listener will be notified and logic to handle the
// signed in user can be handled in the listener.
if (!task.isSuccessful()) {
Toast.makeText(RegisterActivity.this, "Authentication failed." + task.getException(),
Toast.LENGTH_SHORT).show();
} else {
startActivity(new Intent(RegisterActivity.this, WelcomeActivity.class));
finish();
}
}
});
}
});
}
#Override
protected void onResume() {
super.onResume();
progressBar.setVisibility(View.GONE);
}
}
LoginActivity.java
public class LoginActivity extends AppCompatActivity {
private EditText inputEmail, inputPassword;
private FirebaseAuth auth;
private ProgressBar progressBar;
private Button btnLogin, btnReset;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Get Firebase auth instance
auth = FirebaseAuth.getInstance();
if (auth.getCurrentUser() != null) {
startActivity(new Intent(LoginActivity.this, WelcomeActivity.class));
finish();
}
setContentView(R.layout.activity_login);
inputEmail = (EditText) findViewById(R.id.login_email);
inputPassword = (EditText) findViewById(R.id.login_password);
progressBar = (ProgressBar) findViewById(R.id.login_progressBar);
btnLogin = (Button) findViewById(R.id.btn_login);
btnReset = (Button) findViewById(R.id.btn_reset_password);
//Get Firebase auth instance
auth = FirebaseAuth.getInstance();
btnReset.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
resetPassword();
//startActivity(new Intent(LoginActivity.this, ResetPasswordActivity.class));
}
});
btnLogin.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String email = inputEmail.getText().toString();
final String password = inputPassword.getText().toString();
if (TextUtils.isEmpty(email)) {
Toast.makeText(getApplicationContext(), "Enter email address!", Toast.LENGTH_SHORT).show();
return;
}
if (TextUtils.isEmpty(password)) {
Toast.makeText(getApplicationContext(), "Enter password!", Toast.LENGTH_SHORT).show();
return;
}
progressBar.setVisibility(View.VISIBLE);
//authenticate user
auth.signInWithEmailAndPassword(email, password)
.addOnCompleteListener(LoginActivity.this, new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
// If sign in fails, display a message to the user. If sign in succeeds
// the auth state listener will be notified and logic to handle the
// signed in user can be handled in the listener.
progressBar.setVisibility(View.GONE);
if (!task.isSuccessful()) {
// there was an error
if (password.length() < 6) {
inputPassword.setError(getString(R.string.minimum_password));
} else {
Toast.makeText(LoginActivity.this, getString(R.string.auth_failed), Toast.LENGTH_LONG).show();
}
} else {
Intent intent = new Intent(LoginActivity.this, WelcomeActivity.class);
startActivity(intent);
finish();
}
}
});
}
});
}
You can map username to email. For ex, by creating a table of username and email in db. Then, when user enters username to login, fetch corresponding email and use it to perform simple email - password login.
See this Username authentication instead of email
Alternative is to create a server with a Database instead of Firebase.
Everything looks fine to me, I just want to register a user in firebase but it doesn't work. Here is my activity:
public class SignUp extends Activity {
Button signup1;
EditText email1, password1, password2;
FirebaseAuth firebaseAuth;
ProgressDialog progressDialog;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sign_up);
//Instantiate the FirebaseAuth object
firebaseAuth = FirebaseAuth.getInstance();
signup1 = (Button) findViewById(R.id.signup);
// Setting the listener for button
signup1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
register();
}
});
email1 = (EditText) findViewById(R.id.email);
password1 = (EditText) findViewById(R.id.password1);
password2 = (EditText) findViewById(R.id.password2);
progressDialog = new ProgressDialog(this);
}
public void register() {
String email = email1.getText().toString().trim();
String pass1 = password1.getText().toString().trim();
String pass2 = password2.getText().toString().trim();
if (TextUtils.isEmpty(email)) {
Toast.makeText(this, "Please Enter an Email", Toast.LENGTH_SHORT).show();
return;
}
if (TextUtils.isEmpty(pass1)) {
Toast.makeText(this, "Please Enter Password", Toast.LENGTH_SHORT).show();
return;
}
if (TextUtils.isEmpty(pass2)) {
Toast.makeText(this, "Please Enter Password Again", Toast.LENGTH_SHORT).show();
return;
}
if (TextUtils.equals(pass1, pass2)) {
progressDialog.setMessage("Registering....!");
progressDialog.show();
firebaseAuth.createUserWithEmailAndPassword(email, pass2).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
Toast.makeText(SignUp.this,"SignUp Successfully", Toast.LENGTH_SHORT).show();
}
else {
Toast.makeText(SignUp.this, "SignUp Failed... Try Again", Toast.LENGTH_SHORT).show();
}
progressDialog.dismiss();
}
});
}
else {
Toast.makeText(this, "Password does not Match", Toast.LENGTH_SHORT).show();
return;
}
}
}
The application stucks when it goes into "createUserWithEmailAndPassword".
Use try-catch for exception.
For example createUser... method is null and catch it and resolve.
I am trying to make registration to a App in Firebase, but it keeps on saying Unsuccessful.
Here is my code.
public class RegisterActivity extends AppCompatActivity implements View.OnClickListener {
private EditText etEmail;
private EditText etPassword;
private ProgressDialog progressDialog;
private FirebaseAuth firebaseAuth;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
firebaseAuth = FirebaseAuth.getInstance();
if (firebaseAuth.getCurrentUser() != null){
//Start profile activity here.
finish();
startActivity(new Intent(getApplicationContext(), HomeActivity.class));
}
progressDialog = new ProgressDialog(this);
etEmail = (EditText) findViewById(R.id.editTextEmail);
etPassword = (EditText) findViewById(R.id.editTextPassword);
Button btnRegister = (Button) findViewById(R.id.buttonRegister);
assert btnRegister != null;
btnRegister.setOnClickListener(this);
}
#Override
public void onClick(View v) {
registerUser();
}
private void registerUser(){
String email = etEmail.getText().toString().trim();
String password = etPassword.getText().toString().trim();
if (TextUtils.isEmpty(email)){
//Email is empty. Create a toast to enter a email.
Toast.makeText(this, "Please enter your email address.", Toast.LENGTH_SHORT).show();
// return to the email field.
return;
}
if (TextUtils.isEmpty(password)){
//Password is empty. Create a toast to enter a password.
Toast.makeText(this, "Please enter your password.", Toast.LENGTH_SHORT).show();
// return to the password field.
return;
}
progressDialog.setMessage("Registration on Process...");
progressDialog.show();
firebaseAuth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if (task.isSuccessful()){
//User is successfully registered.
Toast.makeText(RegisterActivity.this, "Registration is successful.", Toast.LENGTH_SHORT).show();
//Log in and User will start profile activity.
finish();
startActivity(new Intent(getApplicationContext(), HomeActivity.class));
}else{
progressDialog.dismiss();
Toast.makeText(RegisterActivity.this, "Registration failed. Please try again.", Toast.LENGTH_SHORT).show();
}
}
});
}
}
I tried Login Activity with an email, that I manually created in FirebaseAuth and it was successful. But the registration activity is regularly unsuccessful.
I couldn't find any error in the code. Can you help me please?