解析文件保存错误,“”无法编码未保存的parsefile“

我在Parse上传图片时遇到错误。请帮我解决这个问题。 我尝试了一些Stack溢出问题,但没什么,所以请帮助我,提前谢谢。

当我按提交按钮,然后我收到以下错误。

错误是

java.lag.illegalStateException: Unable to encode an unsaved parsefile 

我的代码是

 bitmapLogo=BitmapFactory.decodeFile(picturePath); ByteArrayOutputStream stream = new ByteArrayOutputStream(); bitmapLogo.compress(Bitmap.CompressFormat.PNG,0, stream); byte[] image = stream.toByteArray(); String filename=etUser.getText().toString()+".png"; ParseFile file = new ParseFile(filename, image); System.out.println("PARSE FILE NAME : "+picturePath); file.saveInBackground(new SaveCallback() { @Override public void done(ParseException e) { if(e!=null){ btSignup.setText(e.getMessage()); } } },new ProgressCallback() { @Override public void done(Integer integer) { btSignup.setText(""+integer); } }); String spin= String.valueOf(spinBCat.getSelectedItem()); ParseUser user = new ParseUser(); user.setUsername(etUser.getText().toString()); user.setPassword(etPass.getText().toString()); user.setEmail(etEmail.getText().toString()); user.put("logoname",etUser.getText().toString()); user.put("blogo",file); user.signUpInBackground(new SignUpCallback() { public void done(ParseException e) { if (e == null) { Toast.makeText(AddBusinessActivity.this,"You are Successfully Signed Up",Toast.LENGTH_LONG).show(); signUpSucess(); } else { Toast.makeText(AddBusinessActivity.this,""+e.getMessage(),Toast.LENGTH_LONG).show(); // Sign up didn't succeed. Look at the ParseException // to figure out what went wrong } } }); 

最后我解决了这个问题。 只需在ProgressCallback方法中添加代码即可

代码是

 bitmapLogo=BitmapFactory.decodeFile(picturePath); ByteArrayOutputStream stream = new ByteArrayOutputStream(); bitmapLogo.compress(Bitmap.CompressFormat.PNG,0, stream); byte[] image = stream.toByteArray(); String filename=etUser.getText().toString()+".png"; ParseFile file = new ParseFile(filename, image); System.out.println("PARSE FILE NAME : "+picturePath); file.saveInBackground(new SaveCallback() { @Override public void done(ParseException e) { if(e!=null){ btSignup.setText(e.getMessage()); } } },new ProgressCallback() { @Override public void done(Integer integer) { String spin= String.valueOf(spinBCat.getSelectedItem()); ParseUser user = new ParseUser(); user.setUsername(etUser.getText().toString()); user.setPassword(etPass.getText().toString()); user.setEmail(etEmail.getText().toString()); user.put("logoname",etUser.getText().toString()); user.put("blogo",file); user.signUpInBackground(new SignUpCallback() { public void done(ParseException e) { if (e == null) { Toast.makeText(AddBusinessActivity.this,"You are Successfully Signed Up",Toast.LENGTH_LONG).show(); signUpSucess(); } else { Toast.makeText(AddBusinessActivity.this,""+e.getMessage(),Toast.LENGTH_LONG).show(); // Sign up didn't succeed. Look at the ParseException // to figure out what went wrong } } }); } });