按下按钮后,为什么我的应用会停止

时间:2016-11-22 11:34:15

标签: java android-studio

这是我注册用户的方式..但它没有向数据库发送任何东西虽然注册完成得很好

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();
                    }
                });

    }

然后这是我的login.activity。我可以很好地登录,但我想知道这个代码使用登录用户是什么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));
                    }
                }
            });

}

2 个答案:

答案 0 :(得分:0)

问题在这里描述:

  

com.fasterxml.jackson.databind.JsonMappingException:不能   实例化类型的值[simple type,class   com.example.moses.bstation.Person]来自String值;没有单一字符串   构造函数/工厂方法

似乎 JSON响应 Person 类之间的映射不正确。

仔细检查您的Person类实现,也请分享您的Person类实现和JSON响应中的示例。

答案 1 :(得分:0)

像这样改变你的人类

slot-definition-name

然后像这样使用它

    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);