【发布时间】:2020-01-09 04:27:16
【问题描述】:
我正在使用 Picasso 在我的 android 应用程序中显示来自服务器的图像。我有 5 个图像 URL(HTTP 表单)从服务器获取并将其存储在字符串值中。如果我向 Picasso 发送正确的链接(.jpg 表单)它运行正确并在我的图像视图中显示我的图像,如果以(.pdf 格式)发送错误的链接,它会在我的图像视图中显示错误,但是当我从服务器传递空值或空值到字符串时,我的应用程序崩溃它的运行if 语句首先,即使它的值为 null 或空 else 语句没有运行我应该在我的代码中更新什么,以便如果我从服务器获取 null 值,我的 imageview 应该显示并且错误和文本视图值应该被更改。
// 仅在我的 If/Else 开始处编写代码:
if (image_fourth != null && image_fourth != ""){
Picasso.get().load(image_fourth).resize(200, 200).placeholder(R.drawable.placeholder).error(R.drawable.error).into(image1);
image1.setVisibility(View.VISIBLE);
buttons.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (image_second == null){
image_2t.setText("Image Not Found");
image_2t.setVisibility(View.GONE);
}
else if (image_second != null){
Picasso.get().load(image_second).resize(200, 200).placeholder(R.drawable.placeholder).error(R.drawable.error).into(image2);
image2.setVisibility(View.VISIBLE);
image_2t.setText("Image 2");
image_2t.setVisibility(View.VISIBLE);
}
}
});
}
else{
image_1t.setText("Image Not Found");
}
【问题讨论】:
-
会出现什么类型的错误?
-
@BharatVankar 如果我的字符串为空,则它指向“Picasso.get().load(image_fourth).resize(200, 200).placeholder(R.drawable.placeholder).error( R.drawable.error).into(image1); "
标签: android android-studio picasso