2017-06-14 74 views
1

我試圖插入用戶的電話號碼,根據他的UID的火力點數據的基礎上,我下面這個教程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的按鈕,該按鈕被設置爲正確重定向,但我的Java文件UserSettingsUpdate有問題,因爲我試圖將用戶重定向到該活動,完全是在登錄和應用程序之後進行的每次崩潰。

+0

你得到哪個錯誤?什麼是控制檯輸出? –

+0

我檢查了運行選項卡,那裏似乎沒有錯誤,一切正常,但每當我嘗試訪問我的UserSettingsUpdate表格時,應用程序只會崩潰@PabloAlbaladejo – Sahil

回答

-1

我看了一下你正在關注的教程,並且使用firebase-database的人是9,而當前版本的Firebase-database是10.0.1,我建議你更新你的gradel並且應該這樣做。