环信的文档写的很简单但是导入easeui后项目中就出问题了java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/os/AsyncTaskCompat;
附上源代码,完美解决。
public class EaseChatRowImage extends EaseChatRowFile {
protected ImageView imageView;
private EMImageMessageBody imgBody;
public EaseChatRowImage(Context context, EMMessage message, int position, BaseAdapter adapter) {
super(context, message, position, adapter);
}
@Override
protected void onInflateView() {
inflater.inflate(message.direct() == EMMessage.Direct.RECEIVE ? R.layout.ease_row_received_picture : R.layout.ease_row_sent_picture, this);
}
@Override
protected void onFindViewById() {
percentageView = (TextView) findViewById(R.id.percentage);
imageView = (ImageView) findViewById(R.id.image);
}
@Override
protected void onSetUpView() {
imgBody = (EMImageMessageBody) message.getBody();
// received messages
if (message.direct() == EMMessage.Direct.RECEIVE) {
return;
}
String filePath = imgBody.getLocalUrl();
String thumbPath = EaseImageUtils.getThumbnailImagePath(imgBody.getLocalUrl());
showImageView(thumbPath, filePath, message);
}
@Override
protected void onViewUpdate(EMMessage msg) {
if (msg.direct() == EMMessage.Direct.SEND) {
if (EMClient.getInstance().getOptions().getAutodownloadThumbnail()) {
super.onViewUpdate(msg);
} else {
if (imgBody.thumbnailDownloadStatus() == EMFileMessageBody.EMDownloadStatus.DOWNLOADING ||
imgBody.thumbnailDownloadStatus() == EMFileMessageBody.EMDownloadStatus.PENDING ||
imgBody.thumbnailDownloadStatus() == EMFileMessageBody.EMDownloadStatus.FAILED) {
progressBar.setVisibility(View.INVISIBLE);
percentageView.setVisibility(View.INVISIBLE);
imageView.setImageResource(R.drawable.ease_default_image);
} else {
progressBar.setVisibility(View.GONE);
percentageView.setVisibility(View.GONE);
imageView.setImageResource(R.drawable.ease_default_image);
String thumbPath = imgBody.thumbnailLocalPath();
if (!new File(thumbPath).exists()) {
// to make it compatible with thumbnail received in previous version
thumbPath = EaseImageUtils.getThumbnailImagePath(imgBody.getLocalUrl());
}
showImageView(thumbPath, imgBody.getLocalUrl(), message);
}
}
return;
}
// received messages
if (imgBody.thumbnailDownloadStatus() == EMFileMessageBody.EMDownloadStatus.DOWNLOADING ||
imgBody.thumbnailDownloadStatus() == EMFileMessageBody.EMDownloadStatus.PENDING) {
if (EMClient.getInstance().getOptions().getAutodownloadThumbnail()) {
imageView.setImageResource(R.drawable.ease_default_image);
} else {
progressBar.setVisibility(View.INVISIBLE);
percentageView.setVisibility(View.INVISIBLE);
imageView.setImageResource(R.drawable.ease_default_image);
}
} else if (imgBody.thumbnailDownloadStatus() == EMFileMessageBody.EMDownloadStatus.FAILED) {
if (EMClient.getInstance().getOptions().getAutodownloadThumbnail()) {
progressBar.setVisibility(View.VISIBLE);
percentageView.setVisibility(View.VISIBLE);
} else {
progressBar.setVisibility(View.INVISIBLE);
percentageView.setVisibility(View.INVISIBLE);
}
} else {
progressBar.setVisibility(View.GONE);
percentageView.setVisibility(View.GONE);
imageView.setImageResource(R.drawable.ease_default_image);
String thumbPath = imgBody.thumbnailLocalPath();
if (!new File(thumbPath).exists()) {
// to make it compatible with thumbnail received in previous version
thumbPath = EaseImageUtils.getThumbnailImagePath(imgBody.getLocalUrl());
}
showImageView(thumbPath, imgBody.getLocalUrl(), message);
}
}
/**
* 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);
注释掉这部分:
// 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);
}
}
}
}
本文提供了一个针对环信EaseUI在处理图片消息时遇到的NoClassDefFoundError问题的解决方案。通过修改EaseChatRowImage类中的异步任务实现方式,确保了图片能够正确加载,同时避免了类找不到的错误。

3177

被折叠的 条评论
为什么被折叠?



