Android 无法对未保存的解析文件进行编码,正在使用ParseUser

Android 无法对未保存的解析文件进行编码,正在使用ParseUser,android,parse-platform,Android,Parse Platform,我正在尝试使用配置文件图片进行注册活动,但我得到一个错误:无法对未保存的解析文件进行编码。我在另一个类中有相同的代码,它没有任何问题 我认为问题可能是使用ParseUser而不是ParseObject。请帮帮我,这是我的密码 public class SignUpActivityStep3 extends ActionBarActivity { public static final String YOUR_APPLICATION_ID = "kuN8ihs88AYhRR1jI

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

我认为问题可能是使用ParseUser而不是ParseObject。请帮帮我,这是我的密码

    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. \n 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.*/

                }

            }
        });

    }
}

在尝试注册用户之前,需要等待解析文件完成保存。您需要这样做:

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.LogInBackGround
方法使用用户和密码登录,要么使用
Parse.enableLocalDatastore(这)以启用自动用户创建和登录。

非常感谢,简短但最有效。