-1

When I try to register my app, an error says I can't sign in. However, I don't see any problems with my code.


This is my register.xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Activities.RegisterActivity"
    android:background="#ffffff">

    <EditText
        android:id="@+id/fullname"
        android:layout_width="265dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginBottom="8dp"
        android:background="@drawable/reg_edittext_style"
        android:ems="10"
        android:hint="Full Name"
        android:inputType="textPersonName"
        app:layout_constraintBottom_toTopOf="@+id/username"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/regUserPhoto"
        app:layout_constraintVertical_bias="1.0" />

    <ImageView
        android:id="@+id/regUserPhoto"
        android:layout_width="280dp"
        android:layout_height="90dp"
        android:layout_marginStart="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginBottom="96dp"
        android:src="@drawable/together_logo"
        app:layout_constraintBottom_toTopOf="@+id/username"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.495"
        app:layout_constraintStart_toStartOf="parent" />

    <android.support.constraint.Guideline
        android:id="@+id/guideline3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_percent="0.58" />

    <EditText
        android:id="@+id/username"
        android:layout_width="265dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginBottom="8dp"
        android:background="@drawable/reg_edittext_style"
        android:ems="10"
        android:hint="Username"
        android:inputType="textPersonName"
        app:layout_constraintBottom_toTopOf="@+id/email"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent" />

    <EditText
        android:id="@+id/regPassword"
        android:layout_width="265dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginBottom="4dp"
        android:background="@drawable/reg_edittext_style"
        android:ems="10"
        android:hint="Password"
        android:inputType="textPassword"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="@+id/guideline3"
        app:layout_constraintVertical_bias="0.044" />

    <EditText
        android:id="@+id/regPassword2"
        android:layout_width="265dp"
        android:layout_height="44dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="12dp"
        android:layout_marginEnd="8dp"
        android:background="@drawable/reg_edittext_style"
        android:ems="10"
        android:hint="Confirm Password"
        android:inputType="textPassword"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/regPassword" />

    <Button
        android:id="@+id/register"
        android:layout_width="140dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginBottom="8dp"
        android:background="@drawable/reg_btn_style"
        android:text="회원가입"
        android:textColor="#ffffff"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.498"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/regPassword2"
        app:layout_constraintVertical_bias="0.453" />

    <ProgressBar
        android:id="@+id/regProgressBar"
        style="?android:attr/progressBarStyle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="@+id/register"
        app:layout_constraintEnd_toEndOf="@+id/register"
        app:layout_constraintHorizontal_bias="0.489"
        app:layout_constraintStart_toStartOf="@+id/register"
        app:layout_constraintTop_toTopOf="@+id/register"
        app:layout_constraintVertical_bias="1.0" />

    <EditText
        android:background="@drawable/reg_edittext_style"
        android:hint="Mail"
        android:id="@+id/email"
        android:layout_width="265dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginBottom="12dp"
        android:ems="10"
        android:inputType="textEmailAddress"
        app:layout_constraintBottom_toTopOf="@+id/guideline3"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent" />


</android.support.constraint.ConstraintLayout>
    
    
    
    
    
    

This is my RegisterActivity:

package com.example.blogapp.Activities;

import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.blogapp.R;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;

import java.util.HashMap;

public class RegisterActivity extends AppCompatActivity {

    EditText username, fullname, email, password, password2;
    Button register;

    FirebaseAuth auth;
    DatabaseReference reference;

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

        register = findViewById(R.id.register);
        username = findViewById(R.id.username);
        fullname = findViewById(R.id.fullname);
        email = findViewById(R.id.email);
        password = findViewById(R.id.regPassword);
        password2 = findViewById(R.id.regPassword2);

        auth = FirebaseAuth.getInstance();





        register.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                String str_username = username.getText().toString();
                String str_fullname = fullname.getText().toString();
                String str_email = email.getText().toString();
                String str_password = password.getText().toString();
                String str_password2 = password2.getText().toString();

                if(TextUtils.isEmpty(str_email) || TextUtils.isEmpty(str_fullname) || TextUtils.isEmpty(str_password)
                        || TextUtils.isEmpty(str_password2)||TextUtils.isEmpty(str_username)){

                    showMessage("빈곳이 없는지 확인해주세요");

                }else if(!str_password.equals(str_password2)){
                    showMessage("Password is not same.");
                }else if(str_password.length() < 6){
                    showMessage("비밀번호의 길이는 6자 이상이어야 합니다.");
                }else{

                    register(str_username, str_fullname, str_email, str_password);

                }

            }
        });



    }



    private void showMessage(String text) {

        Toast.makeText(getApplicationContext(),text,Toast.LENGTH_LONG).show();

    }


    private void register(final String username, final String fullname, String email, String password){
        auth.signInWithEmailAndPassword(email, password)
                .addOnCompleteListener(RegisterActivity.this, new OnCompleteListener<AuthResult>() {
                    @Override
                    public void onComplete(@NonNull Task<AuthResult> task) {
                        if(task.isSuccessful()){
                            FirebaseUser firebaseUser = auth.getCurrentUser();
                            String userid = firebaseUser.getUid();

                            reference = FirebaseDatabase.getInstance().getReference().child("Users").child(userid);

                            HashMap<String, Object> hashMap = new HashMap<>();
                            hashMap.put("id", userid);
                            hashMap.put("username", username.toLowerCase());
                            hashMap.put("fullname", fullname);
                            hashMap.put("bio", "");
                            hashMap.put("imageurl", "https://firebasestorage.googleapis.com/v0/b/blogapp-a9a56.appspot.com/o/users_photos%2Fimage%3A15?alt=media&token=014d5eac-d890-43b1-8d5b-ba5090d5a6db");

                            reference.setValue(hashMap).addOnCompleteListener(new OnCompleteListener<Void>() {
                                @Override
                                public void onComplete(@NonNull Task<Void> task) {
                                    if (task.isSuccessful()){
                                        Intent intent = new Intent(RegisterActivity.this, HomeActivity.class);
                                        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                                        startActivity(intent);
                                    }
                                }
                            });

                        } else{
                            showMessage("What u r input mail can't sign in");
                        }
                    }
                });
    }



}

There is no error showing, just pop up toast message that I can't sign in with that email.

This is what's shown to me:

Error

Lioness100
  • 8,260
  • 6
  • 18
  • 49
MANTAP NARA
  • 13
  • 1
  • 6

3 Answers3

1

Remove

showMessage("What u r input mail can't sign in");,

and replace it with

showMessage(task.getException().getMessage());

peeebeee
  • 2,541
  • 6
  • 21
  • 26
isaaaaame
  • 460
  • 4
  • 9
  • Thank you after i change your code the error show to me 'There is no user record corresponding to this identifier. The user may have been deleted.' But still no error in my console – MANTAP NARA Mar 25 '19 at 12:19
0

Toast needs to be run on the UIThread. However, the callback from your Auth API will happen on another thread (this is good because you don't want you app to hang/freeze while authenticating). There is a discussion on a couple different approaches to running your code on the UIThread here Android basics: running code in the UI thread.

In short, change your showMessage method accordingly

private void showMessage(String text) {
    MainActivity.this.runOnUiThread(new Runnable() {
        public void run() {
            Toast.makeText(getApplicationContext(),text,Toast.LENGTH_LONG).show();
        }
    });
}
Simon
  • 111
  • 1
  • 7
  • Thanks Simon after i change show what error code then Toast write 'There is no user record corresponding to this identifier. The user may have been deleted.' But still no error in my console – MANTAP NARA Mar 25 '19 at 12:20
  • I'm not very much into Firebase, but from the looks of it you are trying to login to a user that does not exist. Maybe you ought to create the user first. Probably you should have two different Android activities for registration and login. Found some user registration documentation for you here https://firebase.google.com/docs/auth/android/password-auth – Simon Mar 25 '19 at 12:28
0

Have you enabled sign In with Email/Password in firebase console? Step to enable: Authentication ->Sign-in method -> Email/Password

Nupur
  • 31
  • 4
  • Yes of courese i think there is no problem in my code.. cuz there is no error in console just popup message show me that 'There is no user record corresponding to this identifier" – MANTAP NARA Mar 26 '19 at 00:55
  • Have you checked that your email id/password which you are trying to log in is exists in firebase console? – Nupur Apr 01 '19 at 08:48