Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

W/System: Ignoring header X-Firebase-Locale because its value was null

Im very new to android studio. I'm trying to make a signup page with email and password authentication with Firebase. Howerver, whenever I try to click the sign up button it gives:

W/System: Ignoring header X-Firebase-Locale because its value was null

Can anyone tell me why?

Here is the SignupActivity.java file

package com.example.traintrack;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.android.material.textfield.TextInputLayout;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;

import java.util.regex.Pattern;

public class SignupActivity extends AppCompatActivity implements AdapterView.OnItemSelectedListener {
    FirebaseAuth fAuth;
    Button signupBtn;       // Signup Button
    private String userType;
    private TextInputLayout textInputFullName;
    private TextInputLayout textInputEmail;
    private TextInputLayout textInputPassword;
    private boolean submitted = false, validUser = false;
    Spinner spinner;
    public static final Pattern VALID_EMAIL_ADDRESS_REGEX =
            Pattern.compile("^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,6}$", Pattern.CASE_INSENSITIVE);

    private String email;
    private String password;


    //Validating the signup page
    private boolean validateName(){
        String name = textInputFullName.getEditText().getText().toString().trim();

        if (name.isEmpty()){
            textInputFullName.setError("Field can't be empty");
        } else{
            textInputFullName.setError(null);
            return true;
        }

        return false;
    }
    private boolean validateEmail(){

        String email = textInputEmail.getEditText().getText().toString().trim();

        if (email.isEmpty()){
            textInputEmail.setError("Field can't be empty");
        } else if (!VALID_EMAIL_ADDRESS_REGEX.matcher(email).find()){
            textInputEmail.setError("Please enter a valid email");
        } else {
            textInputEmail.setError(null);
            return true;
        }
        return false;
    }

    private boolean validatePassword(){
        String password = textInputPassword.getEditText().getText().toString().trim();
        if (password.isEmpty()){
            textInputPassword.setError("Field can't be empty");
        } else if (password.length() < 8){
            textInputPassword.setError("Password must have at least 8 characters");
        } else {
            return true;
        }
        return false;
    }

    //public void confirm(View button){

    //}



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

        spinner = findViewById(R.id.signup_type);
        ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.user_types, android.R.layout.simple_spinner_item);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner.setAdapter(adapter);
        spinner.setOnItemSelectedListener(this);

        textInputFullName = findViewById(R.id.signup_fullname);
        textInputEmail =  findViewById(R.id.signup_email);
        textInputPassword =  findViewById(R.id.signup_password);
        signupBtn = findViewById(R.id.signup_confirm);


        //Firebase, Sign up by clicking the button
        fAuth = FirebaseAuth.getInstance();

        if (fAuth.getCurrentUser() != null)  // when the current user object is already present
          {
             startActivity(new Intent(getApplicationContext(), MainActivity.class));  //back to main page
             finish();
          }

        //register the user in firebase
        signupBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                password = textInputPassword.getEditText().getText().toString().trim();
                email = textInputEmail.getEditText().getText().toString().trim();

                // I have moved the validation here since this is the button for click
                submitted = true;
                if (!validateName() || !validateEmail() || !validatePassword() || !validUser){
                    Toast.makeText(SignupActivity.this, "Cannot create account", Toast.LENGTH_SHORT).show();
                    return;
                }


                fAuth.createUserWithEmailAndPassword(email,password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
                    @Override
                    public void onComplete(@NonNull Task<AuthResult> task) {
                        if (task.isSuccessful()) //successfully created the user
                            {
                            Toast.makeText(SignupActivity.this, "Account created!", Toast.LENGTH_SHORT).show();
                            startActivity(new Intent (getApplicationContext(), MainActivity.class));
                            } else {

                            Toast.makeText(SignupActivity.this, "Error !", Toast.LENGTH_SHORT).show();
                        }
                    }
                });

            }
        });




    }//OnCreated Closing


    @Override
    public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
        String type = parent.getItemAtPosition(position).toString();
        if (type.equals(getResources().getStringArray(R.array.user_types)[0]) && submitted){
            TextView errorText = (TextView)spinner.getSelectedView();
            errorText.setError("");
            errorText.setTextColor(Color.RED);
            errorText.setText("Please select a user type");
        } else {
            validUser = true;
            userType = type;
        }
    }

    @Override
    public void onNothingSelected(AdapterView<?> parent) {

    }

}  //Ending
'''
like image 649
user14245642 Avatar asked Nov 07 '20 12:11

user14245642


1 Answers

Make sure the emulator is connected to the internet. Sometimes the wifi is on but doesnt connect to the internet. This is how i fixed it anyway.

like image 68
Fergal O Connor Avatar answered Sep 20 '22 18:09

Fergal O Connor