gpt4 book ai didi

java - Picasso 显示错误路径一定不能为空?

转载 作者:行者123 更新时间:2023-11-30 12:06:39 28 4
gpt4 key购买 nike

我正在尝试从 firebase 获取图像。所以当 firebase 中没有图像时,我希望我的应用程序 Logo 将设置在那里。但是我的应用程序崩溃了并将错误抛出到日志猫中。

我尝试使用 if-else 条件。以及成功和错误方法。但效果不佳。

private static final String Earnings_Freebies = "EARNINGS_FREEBIES";

private Earnings_Freebies list;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.earnings_freebies);

list = (Earnings_Freebies) getIntent().getExtras().getSerializable(Earnings_Freebies);

if (TextUtils.isEmpty(list.getmImageView())){
m_EF_ImageView.setImageResource(R.drawable.app_logo);
mProgressBarEF.setVisibility(View.GONE);
}

Picasso.with(getApplicationContext())
.load(list.getmImageView())
.into(m_EF_ImageView, new Callback() {
@Override
public void onSuccess() {
mProgressBarEF.setVisibility(View.GONE);
mFailedImage.setVisibility(View.GONE);
}

@Override
public void onError() {
mProgressBarEF.setVisibility(View.GONE);
mFailedImage.setVisibility(View.VISIBLE);

}
});

我想要有错误的时候。或者我忘记将图像放入 firebase,然后应用程序 Logo 将自动设置为 ImageView 。

最佳答案

您可以尝试以下代码。如果没有帮助,请告诉我更多有关 Earnings_Freebies 模型的信息。

确保您使用的是 Picasso 的最新依赖项。

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.earnings_freebies);

list = (Earnings_Freebies) getIntent().getExtras().getSerializable(Earnings_Freebies);

if (list == null && TextUtils.isEmpty(list.getmImageView())){
m_EF_ImageView.setImageResource(R.drawable.app_logo);
mProgressBarEF.setVisibility(View.GONE);

Picasso.with(getApplicationContext())
.load(R.mipmap.ic_launcher) // can also be a drawable
.into(m_EF_ImageView);
} else {
Picasso.with(getApplicationContext())
.load(list.getmImageView())
.placeholder(R.mipmap.ic_launcher) // can also be a drawable
.into(m_EF_ImageView);
}
}

关于java - Picasso 显示错误路径一定不能为空?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55441242/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com