解析文件保存错误,""无法编码未保存的解析文件"

时间:2015-03-15 11:10:23

标签: java android image-processing parse-platform

我在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
            }
        }
    });

1 个答案:

答案 0 :(得分:1)

最后我解决了这个问题。只需在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
        }
    }
});
    }
});