0

I am working in an app that will take input from edit text view and add this to firebase child "Programming". But it is not working, Firebase Realtime Database is not updating.

Rules:

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

Can you tell me where, and what is the problem?

Here is my MainActivity.java

package com.codeavenge.firebaseapp;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.google.android.gms.tasks.OnSuccessListener;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.firestore.DocumentReference;
import com.google.firebase.firestore.FirebaseFirestore;

import java.util.HashMap;
import java.util.Map;

public class MainActivity extends AppCompatActivity {
    private Button button_add,button;
    private EditText editText;

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

        button_add = findViewById(R.id.add);
        editText = findViewById(R.id.txt_add);
        button = findViewById(R.id.logout);


        button.setOnClickListener(view -> {
            FirebaseAuth.getInstance().signOut();
            Toast.makeText(MainActivity.this, "Logout Successful", Toast.LENGTH_SHORT).show();
            startActivity(new Intent(MainActivity.this, StartActivity.class));
        });
        button_add.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String txt_add = editText.getText().toString();
                if (txt_add.isEmpty()){
                    Toast.makeText(MainActivity.this, "Text Field Is Empty", Toast.LENGTH_SHORT).show();
                }else {
                    FirebaseDatabase.getInstance().getReference().child("Programming").push().setValue(txt_add);
                }
            }
        });

    }
}

Here is my activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <EditText
        android:id="@+id/txt_add"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textEmailAddress"
        android:layout_marginStart="32dp"
        android:layout_marginTop="64dp"
        android:layout_marginEnd="32dp"
        android:hint="Type Your Text"/>

    <Button
        android:id="@+id/add"
        android:layout_below="@id/txt_add"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Add Text"
        android:layout_marginTop="20dp"
        android:layout_alignEnd="@id/txt_add"/>

    <Button
        android:layout_marginTop="60dp"
        android:id="@+id/logout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Logout"
        android:layout_marginLeft="30dp"
        android:layout_marginRight="30dp"
        android:textAllCaps="false"
        android:layout_below="@id/add"/>
</RelativeLayout>

Firebase Screenshot

Frank van Puffelen
  • 499,950
  • 69
  • 739
  • 734
Anindra
  • 9
  • 4
  • There are many things that could be going wrong here. Can you check the logcat output of your app to see if there are any relevant messages around the call to `setValue`? – Frank van Puffelen Nov 04 '21 at 14:10
  • 1
    Here is my Logcat https://gist.githubusercontent.com/meanindra/6d8240b25880c1766dbee1bc4e31c0d9/raw/713b975c2da4da79e9f795031c6e0e36e5843d63/gistfile1.txt – Anindra Nov 04 '21 at 14:19
  • The URL in your `google-services.json` is either missing or incorrect. See the question I linked for how to solve that. – Frank van Puffelen Nov 04 '21 at 14:57

0 Answers0