1

I keep having this issue in my code. From the code below, I think I already checked if the load() value is null. If it's null, the code should never reach Picasso.

My app allows users to give comments or upload photos to a dish (like yelp). However, they're not required to post both. So there could be data have only comment or photo. So, I'm not sure if that's something that causes the problem.

This is the database where I wanna retrieve from:

https://ibb.co/ZNTSFb0 enter image description here

To explain my code a little:

  • Check if the dataSnapshot1 has image value;
  • if yes, then check if the dishName matches this dish;
  • if yes, then put the photo on the imageView.

Code:

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);}
            }
        }

    }

I don't have to use Picasso if there's any other easier way. All I want to have on my app is a list of matched photos retrieved from the firebase.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • imageView what's null. check this https://stackoverflow.com/questions/26790301/picasso-illegalargumentexception-target-must-not-be-null – fancyyou Apr 22 '19 at 07:39

1 Answers1

0

Change the following:

if(dataSnapshot1.child("image").getValue()!=null)

Into this:

if(dataSnapshot1.hasChild("image")){ /* code */ }

From the docs:

hasChild(String path) Can be used to determine if this DataSnapshot has data at a particular location

Peter Haddad
  • 78,874
  • 25
  • 140
  • 134