简体   繁体   中英

Retrieving image from firebase (Realtime Database)

I'm trying to retrieve an image from firebase realtime database, but my app keeps crashing when opening it.

Database Structure:

[ https://i.stack.imgur.com/iWOEK.png][1]

Following is my java code:

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: Sending signal. PID: 8763 SIG: 9

确保您已授予对数据库规则的读写权限{ "rules": { ".read": true, ".write": true } }有关更多信息,请参阅

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM