'Android Studio INSERT button not adding
I try to Insert some random values to Realtime Database in Android Studio with Firebase, it says that Data has been inserted when it hasn't. In another class I created a Students Class that contains getters for name ,last name and telephone number. Here's the code:
package com.example.school;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
public class AddPerson extends AppCompatActivity {
EditText addName;
EditText addLastName;
EditText addTel;
Button Insert;
DatabaseReference studentDbRef;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_person);
addName = findViewById(R.id.addName);
addLastName = findViewById(R.id.addLastName);
addTel = findViewById(R.id.addTel);
Insert = findViewById(R.id.Insert);
studentDbRef = FirebaseDatabase.getInstance().getReference();
Insert.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
insertStudentData();
}
});
}
private void insertStudentData(){
String name = addName.getText().toString();
String lastname = addLastName.getText().toString();
String telephone = addTel.getText().toString();
Students students = new Students(name , lastname, telephone);
studentDbRef.setValue(name);
Toast.makeText(AddPerson.this, "Data Inserted", Toast.LENGTH_SHORT).show();
};
}
Solution 1:[1]
Fixed by adjusting Realtime DataBase Firebase rules , it was on test mode at first then i changed both to true.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | FrawnZ |
