我正在尝试将数据输入到parse.com中的custmom列,但我收到错误

时间:2015-04-20 10:31:34

标签: java android parse-platform

我创建了一个用户表,其中包含一个自定义名称字段。

现在每当我尝试将数据放入此字段时,我都会收到错误消息。

我使用的代码是。

ParseUser user = new ParseUser();
                user.setUsername(Name);
                user.setPassword(Password);
                user.setEmail("nevin.george.sunny@gmail.com");


                user.put("Name","test");

                user.signUpInBackground(new SignUpCallback() {
                    @Override
                    public void done(ParseException e) {
                        if (e == null) {
                            // Show a simple Toast message upon successful registration
                            Toast.makeText(getApplicationContext(),
                                    "Successfully Signed up, please log in.",
                                    Toast.LENGTH_LONG).show();
                        } else {
                            Toast.makeText(getApplicationContext(),
                                    "Sign up Error", Toast.LENGTH_LONG)
                                    .show();
                        }
                    }


                });

但是我收到了“注册错误”消息。表中没有更新。

1 个答案:

答案 0 :(得分:1)

下面的代码对我来说在许多项目中都有用(所以我想如果它有帮助我会粘贴)。你从哪里得到'setusername'和'setpassword'?

  public void register(final View v){
    if(mUsernameField.getText().length() == 0 || mPasswordField.getText().length() == 0)
        return;

    v.setEnabled(false);
    ParseUser user = new ParseUser();
    user.setUsername(mUsernameField.getText().toString());
    user.setPassword(mPasswordField.getText().toString());
    //mErrorField.setText("");

    user.signUpInBackground(new SignUpCallback() {
        @Override
        public void done(ParseException e) {
            if (e == null) {
                Intent intent = new Intent(RegisterActivity.this, LoggedIn.class);
                startActivity(intent);
                finish();
            } else {
                // Sign up didn't succeed. Look at the ParseException
                // to figure out what went wrong
                switch(e.getCode()){
                    case ParseException.USERNAME_TAKEN:
                        mErrorField.setText("Sorry, this username has already been taken.");
                        break;
                    case ParseException.USERNAME_MISSING:
                        mErrorField.setText("Sorry, you must supply a username to register.");
                        break;
                    case ParseException.PASSWORD_MISSING:
                        mErrorField.setText("Sorry, you must supply a password to register.");
                        break;
                    default:
                        mErrorField.setText(e.getLocalizedMessage());
                }
                v.setEnabled(true);
            }
        }
    });
}