我想将图像从android上传到php服务器(laravel框架)。当我从图库中选择图片时,我会得到
在空对象引用上调用虚拟方法'int java.lang.String.length()'
命令错误
如果(parseContent.isSuccess(response))
这是我的代码。在创建中:
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent galleryIntent = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(galleryIntent, GALLERY);
}
});
和
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == this.getActivity().RESULT_CANCELED) {
return;
}
if (requestCode == GALLERY) {
if (data != null) {
Uri contentURI = data.getData();
try {
Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getActivity().getContentResolver(), contentURI);
String path = saveImage(bitmap);
uploadImageToServer(path);
//imageview.setImageBitmap(bitmap);
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(view.getContext(), "Failed!", Toast.LENGTH_SHORT).show();
} catch (JSONException e) {
e.printStackTrace();
}
}
}
private void uploadImageToServer(final String path) throws IOException, JSONException {
if (!Utils.isNetworkAvailable(view.getContext())) {
Toast.makeText(view.getContext(), "Internet is required!", Toast.LENGTH_SHORT).show();
return;
}
HashMap<String, String> map = new HashMap<String, String>();
map.put("url", "https://satrapmobile.ir/uploadImage");
map.put("filename", path);
new MultiPartRequester(this.getActivity(), map, GALLERY,this);
Utils.showSimpleProgressDialog(view.getContext());
}
@Override
public void onTaskCompleted(String response, int serviceCode) {
Utils.removeSimpleProgressDialog();
Log.d("res", response.toString());
switch (serviceCode) {
case GALLERY:
***if (parseContent.isSuccess(response))*** {
String url = parseContent.getURL(response);
aQuery.id(imageview).image(url);
}
}
}
在ParseContent类中:
public boolean isSuccess(String response) {
try {
JSONObject jsonObject = new JSONObject(response);
if (jsonObject.optString(KEY_SUCCESS).equals("true")) {
return true;
} else {
return false;
}
} catch (JSONException e) {
e.printStackTrace();
}
return false;
}
请帮助我