[英]Retrieving image from firebase (Realtime Database)
我正在嘗試從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
確保您已授予對數據庫規則的讀寫權限{ "rules": { ".read": true, ".write": true } }
有關更多信息,請參閱此
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.