2016-11-22 75 views
0

這是多麼我已經註冊但沒有發送任何數據庫的users..but雖然登記結束就好爲什麼我的應用程序停止後,我按下按鈕

private void registerUser(){ 



     //getting email and password from edit texts 
     String email = editTextEmail.getText().toString().trim(); 
     String password = editTextPassword.getText().toString().trim(); 

     //checking if email and passwords are empty 
     if(TextUtils.isEmpty(email)){ 
      Toast.makeText(this,"Please enter email",Toast.LENGTH_LONG).show(); 
      return; 
     } 

     if(TextUtils.isEmpty(password)){ 
      Toast.makeText(this,"Please enter password",Toast.LENGTH_LONG).show(); 
      return; 
     } 

     //if the email and password are not empty 
     //displaying a progress dialog 

     progressDialog.setMessage("Registering Please Wait..."); 
     progressDialog.show(); 


     //creating a new user 
     firebaseAuth.createUserWithEmailAndPassword(email, password) 
       .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { 
        @Override 
        public void onComplete(@NonNull Task<AuthResult> task) { 
         //checking if success 
         if(task.isSuccessful()){ 
          finish(); 
          startActivity(new Intent(getApplicationContext(), ProfileActivity.class)); 
         }else{ 
          //display some message here 
          Toast.makeText(MainActivity.this,"Registration Error",Toast.LENGTH_LONG).show(); 
         } 
         progressDialog.dismiss(); 
        } 
       }); 

    } 

那麼這裏就是我的登錄信息。活動。我可以登錄,但很好,但我想知道這是什麼cretiria用於登錄用戶的代碼?

private void userLogin(){ 
    String email = editTextEmail.getText().toString().trim(); 
    String password = editTextPassword.getText().toString().trim(); 


    //checking if email and passwords are empty 
    if(TextUtils.isEmpty(email)){ 
     Toast.makeText(this,"Please enter email",Toast.LENGTH_LONG).show(); 
     return; 
    } 

    if(TextUtils.isEmpty(password)){ 
     Toast.makeText(this,"Please enter password",Toast.LENGTH_LONG).show(); 
     return; 
    } 

    //if the email and password are not empty 
    //displaying a progress dialog 

    progressDialog.setMessage("Registering Please Wait..."); 
    progressDialog.show(); 

    //logging in the user 
    firebaseAuth.signInWithEmailAndPassword(email, password) 
      .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { 
       @Override 
       public void onComplete(@NonNull Task<AuthResult> task) { 
        progressDialog.dismiss(); 
        //if the task is successfull 
        if(task.isSuccessful()){ 
         //start the profile activity 
         finish(); 
         startActivity(new Intent(getApplicationContext(), ProfileActivity.class)); 
        } 
       } 
      }); 

} 
+1

堆棧跟蹤?它是一個特定的按鈕? – MordechayS

+1

發佈logcat錯誤 –

+0

是@MordenachayS這裏是我的mainactivity.xml文件 –

回答

0

改變你的類人這樣

public class Person { 

    private String Username; 
    private String Email; 

    public Person(String email,String userName) { 
    this.Username=userName; 
    this.Email=email; 

     /*Blank default constructor essential for Firebase*/ 
    } 
    //Getters and setters 
    public String getUsername() { 
     return Username; 
    } 

    public void setUsername(String Username) { 
     this.Username = Username; 
    } 

    public String getEmail() { 
     return Email; 
    } 

    public void setEmail(String Email) { 
     this.Email = Email; 
    } 
} 

然後使用它像這樣

Person person=new Person(); 
person.setUsername(Username); 
person.setEmail(Email); 
Firebase newRef = ref.child("Users").push(); 
newRef.setValue(person); 

然後用它來獲取值

newRef.addChildEventListener(new ChildEventListener() { 
      @Override 
      public void onChildAdded(DataSnapshot dataSnapshot, String s) { 
       Person person = dataSnapshot.getValue(Person.class); 
String string = "Username: "+person.getName()+"\nEmail: "+person.getEmail()+"\n\n"; 

      } 

      @Override 
      public void onChildChanged(DataSnapshot dataSnapshot, String s) { 

      } 

      @Override 
      public void onChildRemoved(DataSnapshot dataSnapshot) { 

      } 

      @Override 
      public void onChildMoved(DataSnapshot dataSnapshot, String s) { 

      } 

      @Override 
      public void onCancelled(FirebaseError firebaseError) { 

      } 
     }); 
+0

問題依然存在......數據被髮送到正確的火力點,但該程序之後imediately停止... @ UmarAta –

+0

錯誤是否已更改 –

+0

11-22 21:14:15.522 30892-30892/com.example.moses.bstation E/UncaughtException:com.firebase.client.FirebaseException:無法反彈以在 處鍵入com.firebase.client.DataSnapshot.getValue(DataSnapshot。java:185) at com.example.moses.bstation.MainActivity $ 1 $ 1.onDataChange(MainActivity.java:57) –

0

的問題是在此描述:

com.fasterxml.jackson.databind.JsonMappingException:可以鍵入[簡單類型,類 com.example.moses.bstation的不 實例化值。人]從字符串值;沒有單一的字符串 構造/工廠方法

看來,JSON響應類之間的映射是不正確。

仔細檢查您的Person類的實現,也請分享您的Person類執行情況和JSON響應的樣本。

+0

數據被正確發送到我的火力點,但之後應用程序停止 –

相關問題