美好的一天,我得到了:
com.android.volley.VolleyError:java.lang.NullPointerException: 尝试调用虚方法' int java.lang.String.length()'在...上 null对象引用
这是我的代码
private void volleyImageUpload(String url)
{
Log.d("safasf",lat+ ""+lon);
progressDialog = new ProgressDialog(PictureCommentActivity.this);
progressDialog.setMessage("Uploading data Please wait...");
progressDialog.setCancelable(false);
progressDialog.show();
//converting image to base64 string
ByteArrayOutputStream baos = new ByteArrayOutputStream();
// Bitmap resultBitmap = Bitmap.createBitmap(bitmap, 0, 0, 500, 500);
// Bitmap scaledBitmap = scaleDown(bitmap, 800, true);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] imageBytes = baos.toByteArray();
// long lengthbmp = imageBytes.length;
final String imageString = Base64.encodeToString(imageBytes, Base64.DEFAULT);
Log.v("base 64 == ",imageString);
//sending image to server
StringRequest request = new StringRequest(Request.Method.POST, url, new Response.Listener<String>(){
@Override
public void onResponse(String s) {
progressDialog.dismiss();
Log.d("Respo",s);
// popup
try {
JSONObject object = new JSONObject(s);
if(object.getString("status").equals("0"))
{
ShowMessage.msg(PictureCommentActivity.this, ""+object.getString("status_message"));
}
else{
showConfirmMessage("Congratulations","You Have Successfully Uploaded the Post");
// Intent intent = new Intent(getApplicationContext(),HomeActivity.class);
// startActivity(intent);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
},new Response.ErrorListener(){
@Override
public void onErrorResponse(VolleyError volleyError) {
// Log.d("Respo",volleyError+"");
// Toast.makeText(PictureCommentActivity.this, ""+volleyError.getMessage(), Toast.LENGTH_SHORT).show();
// progressDialog.dismiss();
// showConfirmMessage("Unfortunately","Your Internet Connection is Weak please try Again");
if(volleyError!=null && volleyError.getMessage() !=null){
Toast.makeText(getApplicationContext(),"error VOLLEY "+volleyError.getMessage(),Toast.LENGTH_LONG).show();
}
else{
Toast.makeText(getApplicationContext(),"Something went wrong",Toast.LENGTH_LONG).show();
}
}
}) {
//adding parameters to send
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> parameters = new HashMap<String, String>();
parameters.put("img", imageString);
parameters.put("lat", lat);
parameters.put("lng", lon);
parameters.put("org_id", org);
parameters.put("user_id", id);
parameters.put("usertype",user_type);
parameters.put("cmmt", comments.getText().toString());
return parameters;
}
};
// request.setRetryPolicy(new DefaultRetryPolicy(10000, 0, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
request.setRetryPolicy(new DefaultRetryPolicy(0, -1, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
rQueue.add(request);
}
我已经尝试了很多方法,但没有找到任何解决方案我知道这是堆栈溢出中的常见问题,但是ans won.t帮助我
我的位图代码
int targetW = image.getWidth();
int targetH = image.getHeight();
// Get the dimensions of the bitmap
BitmapFactory.Options bmOptions = new BitmapFactory.Options();
bmOptions.inJustDecodeBounds = true;
BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions);
int photoW = bmOptions.outWidth;
int photoH = bmOptions.outHeight;
Log.d("Respo","targetH "+targetH + "\ntargetW "+targetW + "\nphotoW"+photoW+"\nphotoH"+photoH);
// Determine how much to scale down the image
int scaleFactor = Math.min(photoW/targetW, photoH/targetH);
Log.d("Respo","scaleFactor "+scaleFactor );
// Decode the image file into a Bitmap sized to fill the View
bmOptions.inJustDecodeBounds = false;
bmOptions.inSampleSize = scaleFactor;
bmOptions.inPurgeable = true;
bitmap = BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions);
image.setImageBitmap(bitmap);
// Toast.makeText(this, ""+Build.MANUFACTURER, Toast.LENGTH_SHORT).show();
if ("samsung".contentEquals(Build.MANUFACTURER))// &&
// getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) // && width > height//)
{
// Toast.makeText(this, "hii", Toast.LENGTH_SHORT).show();
image.setRotation(90);
}
我的LOGCAT enter image description here