这是我的代码
public class TestingActivity extends 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: at com.parse.ParseRequest.newTemporaryException(ParseRequest.java:290) 08-29 19:23:28.570 7072-7072/com.appcentricsoftware.bumbysdigital W/System.err: at com.parse.ParseRESTCommand.onResponseAsync(ParseRESTCommand.java:308) 08-29 19:23:28.570 7072-7072/com.appcentricsoftware.bumbysdigital W/System.err: at com.parse.ParseRequest$3.then(ParseRequest.java:137) 08-29 19:23:28.570 7072-7072/com.appcentricsoftware.bumbysdigital W/System.err: at 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: Caused by: org.json.JSONException: 类型为java.lang.String的值无法转换为JSONObject 08-29 19:23:28.578 7072-7072/com.appcentricsoftware.bumbysdigital W/System.err: at org.json.JSON.typeMismatch(JSON.java:111) 08-29 19:23:28.579 7072-7072/com.appcentricsoftware.bumbysdigital W/System.err: at org.json.JSONObject.(JSONObject.java:160) 08-29 19:23:28.579 7072-7072/com.appcentricsoftware.bumbysdigital W/System.err: at org.json.JSONObject.(JSONObject.java:173) 08-29 19:23:28.579 7072-7072/com.appcentricsoftware.bumbysdigital W/System.err: at com.parse.ParseRESTCommand.onResponseAsync(ParseRESTCommand.java:298) 08-29 19:23:28.579 7072-7072/com.appcentricsoftware.bumbysdigital W/System.err: ... 13 more