简体   繁体   中英

firebase realtime database is not storing data and the logcat shows no error

I am learning java and trying to register user's info in firebase realtime database when they register in the app,but the data doesn't get stored in the database and the logcat shows no error so I can't figure out what's the problem.

PS - App is connected to the database & firebase database rules are:

{
"rules": {
".read": true,
".write": true
}
}

here's the SignUp.java file code

package com.example.foodapp;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.google.android.material.textfield.TextInputEditText;
import com.google.android.material.textfield.TextInputLayout;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;

public class SignUp extends AppCompatActivity {

    //variables
    private TextInputLayout regName,regUsername,regEmail,regPhoneNo,regPassword;
    private Button regBtn,regToLogInBtn;

    FirebaseDatabase rootNode;
    DatabaseReference reference;

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

        //hooks
        regName = (TextInputLayout )findViewById(R.id.reg_name);
        regUsername = (TextInputLayout )findViewById(R.id.reg_username);
        regEmail = (TextInputLayout )findViewById(R.id.reg_email);
        regPhoneNo = (TextInputLayout )findViewById(R.id.reg_phoneNo);
        regPassword = (TextInputLayout )findViewById(R.id.reg_password);
        regBtn = (Button)findViewById(R.id.reg_btn);
        regToLogInBtn = (Button)findViewById(R.id.reg_login_btn);

        //save data in firebase using button click
        regBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                rootNode = FirebaseDatabase.getInstance();
                reference = rootNode.getReference("users");

                Log.d("HELLO", "Register Button Clicked");

                //get all value from text fields
               String name = regName.getEditText().getText().toString();
                String username = regUsername.getEditText().getText().toString();
                String email = regEmail.getEditText().getText().toString();
                String phoneNo = regPhoneNo.getEditText().getText().toString();
                String password = regPassword.getEditText().getText().toString();


                UserHelperClass helperClass = new UserHelperClass(name, username, email, phoneNo, password);

               

                reference.child(phoneNo).push().setValue(helperClass);

            }
        });

    }
}

the xml codes are:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent">
<LinearLayout 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=".SignUp"
    android:orientation="vertical"
    android:background="#fff"
    android:padding="20dp">

    <ImageView
        android:layout_width="150dp"
        android:layout_height="150dp"
        android:src="@drawable/logo"
        android:transitionName="logo_name"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Welcome"
        android:textSize="40sp"
        android:fontFamily="@font/bungee"
        android:layout_marginTop="-20dp"
        android:textColor="#000"
        android:transitionName="logo_text"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="SignUp to start your new Journey"
        android:textSize="18sp"
        android:transitionName="logo_desc"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:layout_marginBottom="20dp"
        android:orientation="vertical">

        <com.google.android.material.textfield.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/reg_name"
            android:hint="Full Name"
            style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
            >

            <com.google.android.material.textfield.TextInputEditText

                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="text" />

        </com.google.android.material.textfield.TextInputLayout>
        //-----------------------------------------------------------------

        <com.google.android.material.textfield.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/reg_username"
        app:counterMaxLength="15"
        android:hint="Username"
        style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
            android:transitionName="username_tran">

            <com.google.android.material.textfield.TextInputEditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="text" />

    </com.google.android.material.textfield.TextInputLayout>
        //--------------------------------------------------------------

        <com.google.android.material.textfield.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/reg_email"
            android:hint="Email"
            style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">

            <com.google.android.material.textfield.TextInputEditText

                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="textEmailAddress" />

        </com.google.android.material.textfield.TextInputLayout>
        //-----------------------------------------------------------

        <com.google.android.material.textfield.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/reg_phoneNo"
            android:hint="Phone Number"
            style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">

            <com.google.android.material.textfield.TextInputEditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="number" />

        </com.google.android.material.textfield.TextInputLayout>
        //---------------------------------------------------------

        <com.google.android.material.textfield.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/reg_password"
            android:hint="Password"
            app:passwordToggleEnabled="true"
            style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
            android:transitionName="password_tran">

            <com.google.android.material.textfield.TextInputEditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="textPassword" />

        </com.google.android.material.textfield.TextInputLayout>

    </LinearLayout>

    <Button
        android:id="@+id/reg_btn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#000"
        android:text="GO"
        android:textColor="#fff"
        android:transitionName="button_tran" />

    <Button
        android:id="@+id/reg_login_btn"
        style="?android:attr/borderlessButtonStyle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#00000000"
        android:text="Already have an account? Login"
        android:textColor="#000"
        android:transitionName="login_signup_tran" />

</LinearLayout>
</ScrollView>

```
the database is:
  [1]: https://i.stack.imgur.com/IlaDs.png

you can refer to this question, after reading those answers, the reason of the issue is either you verification id or code is null or empty SHA certificates is not available on firebase app (console)

Exception when authenticating with wrong verification code

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM