无法对未保存的解析文件进行编码,请使用 ParseUser [英] Unable to encode an unsaved parse file, working with ParseUser

查看:27
本文介绍了无法对未保存的解析文件进行编码,请使用 ParseUser的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用个人资料图片进行注册活动,但收到一条错误消息:无法对未保存的解析文件进行编码.我在另一个类中有相同的代码,它没有任何问题.

I'm trying to make a signUp activity with a profile picture, but i get an error stating: Unable to encode an unsaved parse file. I have the same code in another Class and it doesn't have any problems.

我认为问题可能在于使用 ParseUser 而不是 ParseObject.请帮助我,这是我的代码.

I think that the problem could be using ParseUser instead of ParseObject. Please help me, here's my code.

    public class SignUpActivityStep3 extends ActionBarActivity {

    public static final String YOUR_APPLICATION_ID = "kuN8ihs88AYhRR1jIWT9psCGUXxSOveJPqVVsBnq";
    public static final String YOUR_CLIENT_KEY = "vC4eA9CqulpgkxJ7sTPtoPSANkMxFeiFlYXwODYK";

    byte[] Image;
    ParseFile photo = null;
    String User, Pass, Email, Description;

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

        Parse.initialize(this, YOUR_APPLICATION_ID, YOUR_CLIENT_KEY);

        EditText Desc = (EditText) findViewById(R.id.txtDesc);
        Button Finish = (Button) findViewById(R.id.btnFinish);

        Intent intent = getIntent();
        User = intent.getStringExtra("User");
        Pass = intent.getStringExtra("Pass");
        Email = intent.getStringExtra("Email");
        Image = intent.getByteArrayExtra("Image");        

        photo = new ParseFile("userpicture.png", Image);
        photo.saveInBackground();

        savetoParse();


    }

    private void savetoParse() {

        ParseUser user = new ParseUser();
        user.setUsername(User.toString());
        user.setPassword(Pass.toString());
        user.put("Profile", photo);
        user.setEmail(Email.toString());

        user.signUpInBackground(new SignUpCallback() {

            @Override
            public void done(ParseException e) {

                if (e != null) {

                    Toast.makeText(getApplicationContext(),
                            "Saving user failed." + e.getMessage(), Toast.LENGTH_SHORT).show();

                    if (e.getCode() == 202) {

                        Toast.makeText(
                                getApplicationContext(),
                                "Username already taken. 
 Please choose another username.",
                                Toast.LENGTH_LONG).show();

                    }

                } else {

                    Toast.makeText(getApplicationContext(), "User Saved",
                            Toast.LENGTH_SHORT).show();

                    /*Do some things here if you want to.*/

                }

            }
        });

    }
}

推荐答案

在尝试注册用户之前,您需要等待 Parse 文件完成保存.你需要做这样的事情:

You need to wait for the Parse file to finish saving before attempting to sign up the user. You need to do something like this:

photo = new ParseFile("userpicture.png", Image);

file.saveInBackground(new SaveCallback() {
    public void done(ParseException e) {
       // If successful add file to user and signUpInBackground
       if(null == e)
           savetoParse();
    }
});

这篇关于无法对未保存的解析文件进行编码,请使用 ParseUser的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆