user13286210
user13286210

Reputation:

Data is not uploading in Firebase database from Android

I've followed a tutorial on youtube on inserting data into Firebase database. I've created Member class:

package com.example.bazadanych;

public class Member {
    private String name;
    private String age;
    private String phoneNumber;
    private String height;

    public Member() {
    }

    public String getName() {
        return name;
    }

    public String getAge() {
        return age;
    }

    public String getPhoneNumber() {
        return phoneNumber;
    }

    public String getHeight() {
        return height;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setAge(String age) {
        this.age = age;
    }

    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }

    public void setHeight(String height) {
        this.height = height;
    }
}

And I created code in MainActivity:

public class MainActivity extends AppCompatActivity {
    EditText editName, editPhone, editAge, editHeight;
    Button btnSave;
    DatabaseReference ref;
    Member member;

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

        editName = (EditText) findViewById(R.id.editName);
        editAge = (EditText) findViewById(R.id.editAge);
        editPhone = (EditText) findViewById(R.id.editPhone);
        editHeight = (EditText) findViewById(R.id.editHeight);
        btnSave = (Button) findViewById(R.id.buttonSave);
        ref = FirebaseDatabase.getInstance().getReference().child("Member");

        member = new Member();

        btnSave.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String name = editName.getText().toString().trim();
                String age = editAge.getText().toString().trim();
                String height = editHeight.getText().toString().trim();
                String phone = editPhone.getText().toString().trim();

                member.setName(name);
                member.setAge(age);
                member.setHeight(height);
                member.setPhoneNumber(phone);

                ref.push().setValue(member);

            }
        });
    }

The problem is I can't see data on website. I enabled writing and reading by passing true value on the website. I've connected my app to Firebase and add database to my project. I don't know where the problem is. Anybody can help me?

Upvotes: 0

Views: 400

Answers (1)

paul035
paul035

Reputation: 327

Your code seems correct. I've also checked it over my system and it is getting stored over the firebase. this is the output of your code
May be there is error in your activity_main.xml file.
Can you please provide your activity_main.xml file.

There is naming error in EditText id of phoneNumber in the activity_main.xml which is not same as in MainActivity.java when it is initialized in onCreate() method. Make both of them same.
See the difference
MainActivity.java and activity_main.xml

Upvotes: 1

Related Questions