无法更新firebase数据库中的数据

时间:2017-06-14 06:37:19

标签: android firebase firebase-realtime-database firebase-storage

我正在尝试根据他的UID将用户的电话号码插入firebase数据库,我正在关注本教程this这里是我的代码,

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

        mAuth = FirebaseAuth.getInstance();
        UserName = (EditText) findViewById(R.id.username);
        phoneNumber = (EditText) findViewById(R.id.phonenumber);
        submit = (Button) findViewById(R.id.update);
        dbr = FirebaseDatabase.getInstance().getReference();
        progressDialoge = new ProgressDialog(UserSettingsUpdate.this);


        submit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //updating the data in the user feild
                String username = UserName.getText().toString().trim().toLowerCase();
                String phonenumber = phoneNumber.getText().toString().trim();
                UserInformation userInformation = new UserInformation(username,phonenumber);
                //getting the current user and updating the details to his/her UID
                progressDialoge.setMessage("Updating settings");
                progressDialoge.show();
                FirebaseUser currentUser = mAuth.getCurrentUser();
                dbr.child(currentUser.getUid()).setValue(userInformation);
                progressDialoge.dismiss();
                Toast.makeText(UserSettingsUpdate.this, "its being updated", Toast.LENGTH_LONG).show();
                startActivity(new Intent(UserSettingsUpdate.this, MainActivity.class));
            }
        });

    }
}

所有库都是有序的,在本教程中,使用数据库所需的变量创建一个新的java类,这里是java类,

public class UserInformation {
    public String username;
    public String PhoneNumber;

    public void UserInformation(){

    }

    public UserInformation(String username, String phoneNumber) {
        this.username = username;
        PhoneNumber = phoneNumber;
    }
}

这是XML代码,

<EditText
        android:id="@+id/phonenumber"
        android:layout_width="368dp"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginTop="8dp"
        android:hint="Phone Number"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/username"
        app:layout_constraintVertical_bias="0.123" />

    <EditText
        android:id="@+id/username"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginTop="133dp"
        android:layout_weight="1"
        android:hint="Username"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/update"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginTop="7dp"
        android:text="Submit"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/phonenumber"
        app:layout_constraintVertical_bias="0.152" />
在MainActivity上有一个启动UpdateUserSettings Activity的按钮,按钮设置为正确重定向我的UserSettingsUpdate的Java文件有问题,因为我尝试在登录后将用户重定向到此活动该应用程序每次都崩溃。

1 个答案:

答案 0 :(得分:-1)

我看了你正在关注的教程,使用firebase-database的人是9,Firebase数据库的当前版本是10.0.1,我建议你更新你的年级,这应该做。