这是我的密码
公共类TestingActivity扩展了AppCompatActivity{
Button btn_testing;
ProgressDialog pDialog;
ImageView iv_image;
Bitmap bMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.testing);
btn_testing = (Button)findViewById(R.id.btn_testing);
iv_image = (ImageView)findViewById(R.id.iv_imagetesting);
FileInputStream in;
BufferedInputStream buf;
try
{
in = new FileInputStream("/storage/emulated/0/Pictures/InstaTag_Edit_20160427_131230-346274175.jpg");
buf = new BufferedInputStream(in,1070);
System.out.println("1.................."+buf);
byte[] bMapArray= new byte[buf.available()];
buf.read(bMapArray);
bMap = BitmapFactory.decodeByteArray(bMapArray, 0, bMapArray.length);
iv_image.setImageBitmap(bMap);
if (in != null)
{
in.close();
}
if (buf != null)
{
buf.close();
}
}
catch (Exception e) {
Log.e("Error reading file", e.toString());
}
btn_testing.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
pDialog = new ProgressDialog(TestingActivity.this);
pDialog.setMessage("Loading...");
pDialog.show();
Bitmap bitmap = ((BitmapDrawable)iv_image.getDrawable()).getBitmap();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
// Compress image to lower quality scale 1 - 100
bMap.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] image = stream.toByteArray();
ParseFile file = new ParseFile("androidbegin.png", image,"image/png");
file.saveInBackground(new SaveCallback() {
@Override
public void done(ParseException e) {
try {
pDialog.dismiss();
} catch (Exception e1) {
}
if (e == null) {
Toast.makeText(TestingActivity.this, "Image saved", Toast.LENGTH_LONG).show();
} else {
e.printStackTrace();
Toast.makeText(TestingActivity.this, "Image not saved", Toast.LENGTH_LONG).show();
}
}
});
}
});
}
}
以下是我的日志响应:
08-29 19:23:28.569 7072-7072/com.appcentricsoftware.bumbysdigital w/system.err:com.parse.parserequest$parserequestexception:错误的json响应
08-29 19:23:28.570 7072-7072/com.appcentricsoftware.bumbysdigital w/system.err:位于com.parse.parserequest.newTemporaryException(parserequest.java:290)
08-29 19:23:28.570 7072-7072/com.appcentricsoftware.bumbysdigital w/system.err:在com.parse.parserestcommand.onresponseAsync(parserestcommand.java:308)
08-29 19:23:28.570 7072-7072/com.appcentricsoftware.bumbysdigital w/system.err:com.parse.parserequest$3.then(parserequest.java:137)
08-29 19:23:28.570 7072-7072/com.appcentricsoftware.bumbysdigital w/system.err:com.parse.parserequest$3.then(parserequest.java:133)
08-29 19:23:28.570 7072-7072/com.appcentricsoftware.bumbysdigital w/system.err:at bolts.task$15.run(task.java:917)
08-29 19:23:28.570 7072-7072/com.appcentricsoftware.bumbysdigital w/system.err:at bolts.boltsExecutors$immediateExecutor.execute(boltsExecutors.java:105)
08-29 19:23:28.570 7072-7072/com.appcentricsoftware.bumbysdigital w/system.err:at bolts.task.completeaftertask(task.java:908)
08-29 19:23:28.570 7072-7072/com.appcentricsoftware.bumbysdigital w/system.err:at bolts.task.continueWithtask(task.java:715)
08-29 19:23:28.570 7072-7072/com.appcentricsoftware.bumbysdigital w/system.err:at bolts.task.continueWithtask(task.java:726)
08-29 19:23:28.570 7072-7072/com.appcentricsoftware.bumbysdigital w/system.err:at bolts.task$13.then(task.java:818)
08-29 19:23:28.571 7072-7072/com.appcentricsoftware.bumbysdigital w/system.err:at bolts.task$13.then(task.java:806)
08-29 19:23:28.571 7072-7072/com.appcentricsoftware.bumbysdigital w/system.err:at bolts.task$15.run(task.java:917)
08-29 19:23:28.571 7072-7072/com.appcentricsoftware.bumbysdigital w/system.err:at java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1113)
08-29 19:23:28.571 7072-7072/com.appcentricsoftware.bumbysdigital w/system.err:at java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:588)
08-29 19:23:28.571 7072-7072/com.appcentricsoftware.bumbysdigital w/system.err:at java.lang.thread.run(thread.java:818)
08-29 19:23:28.571 7072-7072/com.appcentricsoftware.bumbysdigital w/system.err:原因:org.json.jsonexception:java.lang.string类型的值无法转换为jsonobject
08-29 19:23:28.578 7072-7072/com.appcentricsoftware.bumbysdigital w/system.err:位于org.json.json.typemismatch(json.java:111)
08-29 19:23:28.579 7072-7072/com.appcentricsoftware.bumbysdigital w/system.err:位于org.json.jsonobject。(jsonobject.java:160)
08-29 19:23:28.579 7072-7072/com.appcentricsoftware.bumbysdigital w/system.err:位于org.json.jsonobject。(jsonobject.java:173)
08-29 19:23:28.579 7072-7072/com.appcentricsoftware.bumbysdigital w/system.err:com.parse.parserestcommand.onresponseAsync(parserestcommand.java:298)
08-29 19:23:28.579 7072-7072/com.appcentricsoftware.bumbysdigital w/system.err:…13更多
最佳答案
更改此行
ParseFile file = new ParseFile("androidbegin.png", image,"image/png");
到
ParseFile file = new ParseFile("androidbegin.png", image);
你加上这些行了吗?
ParseObject photo = new ParseObject("Photo");
photo.put("fileFull", imgfile);
photo.put("User", ParseUser.getCurrentUser());
photo.saveInBackground();