I made a Firebase database with links (these are links to my Storage with some images)
The Storage:
I try to connect to my database and get the value of Page_1 for example by pushing a button
private DatabaseReference mRef;
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mRef = FirebaseDatabase.getInstance().getReference().child("Chapters").child("Chapter 1").child("Page_1");
mRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
String value = String.valueOf(dataSnapshot.getValue());
textView.setText(value);
Picasso.get().load(value).into(page_holder);
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
});
But when I run my app there is an exception and Picasso line says that:
Target must not be null.
If I remove my picasso and only place value of Page_1 into textView it shows the correct value (so it means that I actually get my value and it is not null)
(sorry for the black pattern, I think that the lines might contain something important like a name of database (most likely not but I am a noob in stuff like that))
PS The one thing I noticed is that when I get my value of Page_1 into TextView there is a little delay there. So I guess that Picasso is trying to get "Target" before it is loaded. I tried to make something like a checker
String value_from_database = textView.getText().toString();
if (TextUtils.isEmpty(value_from_database)){
textView.setText("Image is loading|Doesn't exist");
}
else {
Picasso.get().load(value_from_database).into(page_holder);
}
But I still fail. And Picasso shows the same exception/error.
Please, tell me how can I solve it?