错误提示:
环信的文档写的很简单但是导入easeui后项目中就出问题了java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/os/AsyncTaskCompat;
试了网上的解决方案:
把EaseChatRowImage 在这个类替换为
new AsyncTask<Object, Void, Bitmap>() {
@Override
protected Bitmap doInBackground(Object... args) {
File file = new File(thumbernailPath);
if (file.exists()) {
return EaseImageUtils.decodeScaleImage(thumbernailPath, 160, 160);
} else if (new File(imgBody.thumbnailLocalPath()).exists()) {
return EaseImageUtils.decodeScaleImage(imgBody.thumbnailLocalPath(), 160, 160);
}else {
if (message.direct() == EMMessage.Direct.SEND) {
if (localFullSizePath != null && new File(localFullSizePath).exists()) {
return EaseImageUtils.decodeScaleImage(localFullSizePath, 160, 160);
} else {
return null;
}
} else {
return null;
}
}
}
protected void onPostExecute(Bitmap image) {
if (image != null) {
imageView.setImageBitmap(image);
EaseImageCache.getInstance().put(thumbernailPath, image);
} else {
if (message.status() == EMMessage.Status.FAIL) {
if (isNetWorkConnected(activity)) {
new Thread(new Runnable() {
@Override
public void run() {
EMClient.getInstance().chatManager().downloadThumbnail(message);
}
}).start();
}
}
}
}
}.execute();
但是 我试了 还是么有用啊
经过尝试重新这个方法,终于解决了
附上源代码,完美解决。
/**
* load image into image view
*/
private void showImageView(final String thumbernailPath, final String localFullSizePath, final EMMessage message) {
// first check if the thumbnail image already loaded into cache s
Bitmap bitmap = EaseImageCache.getInstance().get(thumbernailPath);
if (bitmap != null) {
// thumbnail image is already loaded, reuse the drawable
imageView.setImageBitmap(bitmap);
} else {
imageView.setImageResource(R.drawable.ease_default_image);
DownLoadImageTask downLoadImageTask=new DownLoadImageTask();
downLoadImageTask.execute(new String[]{thumbernailPath,localFullSizePath});
// AsyncTaskCompat.executeParallel(new AsyncTask<Object, Void, Bitmap>() {
//
// @Override
// protected Bitmap doInBackground(Object... args) {
// File file = new File(thumbernailPath);
// if (file.exists()) {
// return EaseImageUtils.decodeScaleImage(thumbernailPath, 160, 160);
// } else if (new File(imgBody.thumbnailLocalPath()).exists()) {
// return EaseImageUtils.decodeScaleImage(imgBody.thumbnailLocalPath(), 160, 160);
// } else {
// if (message.direct() == EMMessage.Direct.SEND) {
// if (localFullSizePath != null && new File(localFullSizePath).exists()) {
// return EaseImageUtils.decodeScaleImage(localFullSizePath, 160, 160);
// } else {
// return null;
// }
// } else {
// return null;
// }
// }
// }
//
// protected void onPostExecute(Bitmap image) {
// if (image != null) {
// imageView.setImageBitmap(image);
// EaseImageCache.getInstance().put(thumbernailPath, image);
// }
// }
// });
}
}
class DownLoadImageTask extends AsyncTask<String, Void, Bitmap> {
String s= "";
@Override
protected Bitmap doInBackground(String... params) {
s=params[0];
File file = new File(params[0]);
if (file.exists()) {
return EaseImageUtils.decodeScaleImage(params[0], 160, 160);
} else if (new File(imgBody.thumbnailLocalPath()).exists()) {
return EaseImageUtils.decodeScaleImage(imgBody.thumbnailLocalPath(), 160, 160);
} else {
if (message.direct() == EMMessage.Direct.SEND) {
if (params[1] != null && new File(params[1]).exists()) {
return EaseImageUtils.decodeScaleImage(params[2], 160, 160);
} else {
return null;
}
} else {
return null;
}
}
}
protected void onPostExecute(Bitmap image) {
if (image != null) {
imageView.setImageBitmap(image);
EaseImageCache.getInstance().put(s, image);
}
}
}
转载自:https://blog.csdn.net/yuge8930/article/details/79483001