我的代码中一直有这个问题。从下面的代码中,我想我已经检查了load()值是否为null。如果它为null,则代码永远不会到达Picasso。
我的应用程序允许用户发表评论或将照片上传到菜肴(如yelp)。但是,他们不需要发布两者。所以可能有数据只有评论或照片。所以,我不确定这是否会导致问题。
这是我想从中检索的数据库:
稍微解释一下我的代码:
码:
mdatabaseReferece1 = FirebaseDatabase.getInstance().getReference("Post");
mdatabaseReferece1.addValueEventListener(new ValueEventListener() {
@Override
for (DataSnapshot dataSnapshot1 : dataSnapshot.getChildren()){
if (dataSnapshot1.child("image").getValue()!=null){
if (dataSnapshot1.child("dishName").getValue().toString().equals(newDish)) {
ImageView imageView = findViewById(R.id.gallery_photo);
Picasso.get().load(dataSnapshot1.child("image").getValue().toString()).into(imageView);
gallery.addView(view);}
}
}
}
如果还有其他更简单的方法,我不必使用毕加索。我希望在我的应用程序上拥有的是从firebase中检索到的匹配照片列表。
更改以下内容:
if(dataSnapshot1.child("image").getValue()!=null)
进入:
if(dataSnapshot1.hasChild("image")){ /* code */ }
来自文档:
hasChild(String path)
可用于确定此DataSnapshot是否在特定位置具有数据