解析文件保存错误,“"无法在用户中编码未保存的解析文件 [英] Parse file saving error,“”Unable to encode an unsaved parsefile in User

查看:64
本文介绍了解析文件保存错误,“"无法在用户中编码未保存的解析文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用图片为用户注册,但我不断收到错误无法对未保存的解析文件进行编码",当我再次单击保存时,它说用户已经注册,但永远无法解析.

I am trying to sign up a user with a picture and I keep getting the error "Unable to encode an unsaved parsefile", And when I click save again it says a user is already signing up but it never gets to parse.

我的代码如下

imageToBeSent = ((BitmapDrawable) image.getDrawable()).getBitmap();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
imageToBeSent.compress(Bitmap.CompressFormat.PNG,5, stream);    
byte[] imageRec = stream.toByteArray();
ParseFile file = new ParseFile("profile.png", imageRec);


file.saveInBackground();

Intent fromFirstSignup = getIntent();
ParseUser user = new ParseUser();
user.put("Name", fromFirstSignup.getStringExtra("Name"));
user.put("Surname", fromFirstSignup.getStringExtra("Surname"));
user.put("Department", fromFirstSignup.getStringExtra("Department"));
user.put("JobTitle", fromFirstSignup.getStringExtra("JobTitle"));
user.setEmail(fromFirstSignup.getStringExtra("EmailAddress"));
user.put("ProfilePictures", file);
user.setUsername(usernametxt);
user.setPassword(passwordtxt);

user.signUpInBackground(new SignUpCallback() {
    public void done(ParseException e) {
        if (e == null) {
        }
    }
}

其他变量的初始化可能不显示.我确实查看了与此类似的其他问题,但没有一个对我的问题有帮助.

The initializing of other variables may not show. I did look at the other questions similar to this but none helped with my problem.

推荐答案

您收到此错误是因为您无法在 PFObject/PFUser/PFWhatever 中附加未保存的 PFFile.

You’re getting this error because you cannot attach an unsaved PFFile in a PFObject/PFUser/PFWhatever.

您必须等到 file.saveInBackground 完成,然后再保存您的用户.

You have to wait until the file.saveInBackground finishes and then save your User later.

我建议您实现 file.saveInBackgroundWithBlock,并将您的注册代码放在完成块中.

I suggest that you implement the file.saveInBackgroundWithBlock, and put your Sign Up code inside the completion blocks.

这篇关于解析文件保存错误,“"无法在用户中编码未保存的解析文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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