我正在尝试从Firebase实时数据库中检索图像,但是我的应用在打开图像时始终崩溃。
数据库结构:
[https://i.stack.imgur.com/iWOEK.png][1]
以下是我的Java代码:
public class main2 extends AppCompatActivity {
TextView txt, url;
Button btn;
ImageView img;
private FirebaseDatabase firebaseDatabase = FirebaseDatabase.getInstance();
private DatabaseReference reference = firebaseDatabase.getReference();
private DatabaseReference childreference = reference.child("url");
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
url = findViewById(R.id.text);
img = findViewById(R.id.image);
txt = (TextView) findViewById(R.id.mytext);
btn = (Button) findViewById(R.id.mybutton);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
btn.setVisibility(View.GONE);
txt.setText("JOINED, Details will be send by notification.");
}
});
}
@Override
protected void onStart() {
super.onStart();
childreference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
String message = dataSnapshot.getValue(String.class);
url.setText(message);
Picasso.get()
.load(message)
.into(img);
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
}
Logcat:
I / Process:正在发送信号。 PID:8763 SIG:9