Reputation: 12803
I got the Firebase Android Tutorial from here and followed every single step in this tutorial. However, when I click create button
and refresh the firebase
, the database data I get is always empty.
Can someone help me in figuring out what's the problem?
This is my firebase
Config.java
public class Config {
public static final String FIREBASE_URL = "https://healthy-app-30d65.firebaseio.com/";
}
Register
public class Register extends AppCompatActivity {
EditText editTextName;
EditText editTextAddress;
TextView textViewPersons;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.register);
Firebase.setAndroidContext(this);
Button buttonSave = (Button) findViewById(R.id.buttonSave);
editTextName = (EditText) findViewById(R.id.editTextName);
editTextAddress = (EditText) findViewById(R.id.editTextAddress);
textViewPersons = (TextView) findViewById(R.id.textViewPersons);
//Click Listener for button
buttonSave.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Creating firebase object
Firebase ref = new Firebase(Config.FIREBASE_URL);
//Getting values to store
String name = editTextName.getText().toString().trim();
String address = editTextAddress.getText().toString().trim();
//Creating Person object
Person person = new Person();
//Adding values
person.setName(name);
person.setAddress(address);
//Storing values to firebase
ref.child("Person").setValue(person);
}
});
}
}
Upvotes: 1
Views: 3479
Reputation: 598728
You're using a tutorial that was written for the legacy Firebase console (firebase.com) and SDK version (2.x). But your Firebase project was created on the new Firebase console (firebase.google.com).
While most of the API will continue to work, there are a few differences that are hitting you here:
projects created on the new console are configured to only allow authenticated users to read/write. The simplest way to (temporarily) work around this problem is to read the first note in blue on this documentation page. That explains how to make your database world readable/writeable again.
the authentication from the Firebase 2.x SDK will not work against projects created on the new Firebase console.
So #1 may be a good quick workaround, but you really should take an updated tutorial, such as the ones suggested in other answers.
Upvotes: 3
Reputation: 870
The new Firebase is not compatible with legacy code (https://wwww.firebase.com), you'll have to setup your Android project to the latest SDK. You may refer to this link on how to migrate your database code.
Upvotes: 0
Reputation: 878
I suggest you follow the latest firebase samples. You can find step-by-step setup and sample project at Google Firebase Codelab
For example, storing values to real time database is updated
from ref.child("Person").setValue(person);
to ref.child("Person").push().setValue(person);
Upvotes: 0