我正在尝试使用picasso库在mediastore中加载图像存储。当我调用load(imageview,callback)时,毕加索调用onFail而不是onSuccess。我如何知道图像未成功加载的原因?
答案 0 :(得分:156)
使用构建器:
Picasso.Builder builder = new Picasso.Builder(this);
builder.listener(new Picasso.Listener()
{
@Override
public void onImageLoadFailed(Picasso picasso, Uri uri, Exception exception)
{
exception.printStackTrace();
}
});
builder.build().load(URL).into(imageView);
修改强>
对于版本2.71828,他们已将异常添加到onError回调中:
Picasso.get()
.load("yoururlhere")
.into(imageView, new Callback() {
@Override
public void onSuccess() {
}
@Override
public void onError(Exception e) {
}
})
答案 1 :(得分:11)
当你使用回调时,picaso将调用方法onSuccess和onError!
File fileImage = new File(mPathImage);
Picasso.with(mContext).load(fileImage)
.placeholder(R.drawable.draw_detailed_view_display)
.error(R.drawable.draw_detailed_view_display)
.resize(200, 200)
.into(holder.mImageEvidence, new Callback() {
@Override
public void onSuccess() {
holder.mMediaEvidencePb.setVisibility(View.GONE);
}
@Override
public void onError() {
holder.mErrorImage.setVisibility(View.VISIBLE);
}
});
答案 2 :(得分:3)
您是否在[[1, 2, 3, 4], [3, 4, 5, 6]]
添加了互联网权限?凯文回答here,请查看异常日志并在此处发布例外。
答案 3 :(得分:0)
UPDATE STUDENT_BASE
SET NAME = :name
WHERE ID = :id
AND BR_NO = :brNo
答案 4 :(得分:0)
请尝试检查毕加索的日志
Picasso.with(getContext()).setLoggingEnabled(true);
答案 5 :(得分:0)
You have use picasso exception handler. Because if you are to use traditional exception handler(try / catch) it wont catch the actual exception.
var imgURL = Your image url
var imgHolder = Id of your image view
val picasso = Picasso.Builder(this@yourActivity)
.listener { picasso, uri, exception ->
//Here your log - Log cat - error
Log.e("Exception ", exception.stackTraceToString())
}
.build()
picasso.load(imgURL)
.fit()
.into(imgHolder)