Firebase - получение URL изображения - PullRequest
0 голосов
/ 27 июня 2019

Я пытаюсь показать изображение, которое я сохранил в базе данных Firebase.

Когда я пытаюсь прочитать URL моего изображения, он возвращает null.Имя можно прочитать, потому что оно показывает имя ..

Почему это происходит?А как получить URL изображения, сохраненный в базе данных Firebase?

enter image description here

Основная активность:

public class MyPetListActivity extends AppCompatActivity {

    private static String TAG = "MyPetListActivity";


    FirebaseUser firebaseUser;
    DatabaseReference reference;
    Button petadd;
    List<Pet> lsPet;

    ImageView backTo; // layout : activity_my_pet_list.xml


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_pet_list);

        firebaseUser = FirebaseAuth.getInstance().getCurrentUser();

        petadd = findViewById(R.id.petadd);
        backTo = findViewById(R.id.backTo);  //activity_my_pet_list뒤로 가기 버튼

        lsPet = new ArrayList<>();


        reference = FirebaseDatabase.getInstance().getReference("Pets").child(firebaseUser.getUid());
        reference.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                for (DataSnapshot childSnapshot : dataSnapshot.getChildren())
                {
                    String key = childSnapshot.getKey();
                    Log.d(TAG,key+"키키키");
                    Pet pet = childSnapshot.getValue(Pet.class);

                    pet.getPetname();
                    pet.getPetimagerul();

                    Log.wtf(TAG, "did you get name?"+pet.getPetname());
                    Log.wtf(TAG, "did u get image url?"+pet.getPetimagerul());
                    lsPet.add(pet);
                }

                RecyclerView recyclerview_dogs = (RecyclerView) findViewById(R.id.recyclerview_dogs);
                PetAdapter petAdapter = new PetAdapter(MyPetListActivity.this,lsPet);
                recyclerview_dogs.setLayoutManager(new GridLayoutManager(MyPetListActivity.this,3));
                recyclerview_dogs.setAdapter(petAdapter);

            }


            @Override
            public void onCancelled(@NonNull DatabaseError databaseError) {
                Log.wtf(TAG, "onCancelled: 펫이미지 가져오는데 문제 발생! ");
            }
        });

Журнал :

2019-06-27 14:54:15.291 5993-5993/com.example.blogapp E/MyPetListActivity: did u get image url?null
2019-06-27 14:54:15.295 5993-5993/com.example.blogapp W/ClassMapper: No setter/field for petimageurl found on class com.example.together.Model.Pet
2019-06-27 14:54:15.295 5993-5993/com.example.blogapp E/MyPetListActivity: did you get name?SmileDog
2019-06-27 14:54:15.298 5993-5993/com.example.blogapp E/MyPetListActivity: did u get image url?null
2019-06-27 14:54:15.301 5993-5993/com.example.blogapp W/ClassMapper: No setter/field for petimageurl found on class com.example.together.Model.Pet
2019-06-27 14:54:15.301 5993-5993/com.example.blogapp E/MyPetListActivity: did you get name?NullDog
2019-06-27 14:54:15.317 5993-5993/com.example.blogapp E/MyPetListActivity: did u get image url?null
2019-06-27 14:54:15.319 5993-5993/com.example.blogapp W/ClassMapper: No setter/field for petimageurl found on class com.example.together.Model.Pet
2019-06-27 14:54:15.319 5993-5993/com.example.blogapp E/MyPetListActivity: did you get name?Cute Dog ~
2019-06-27 14:54:15.327 5993-5993/com.example.blogapp E/MyPetListActivity: did u get image url?null

Модель:

package com.example.together.Model;

public class Pet {

    private String petimageurl;
    private String petname;
    private String petbreed;
    private String petweight;
    private String birthday;
    private String gender;
    private String intro;
    private String petid;



    public Pet(){

    }

    public Pet(String petimageurl, String petname){
        this.petimageurl = petimageurl;
        this.petname = petname;

    }


    public Pet(String petimageurl, String petname, String intro){
        this.petimageurl = petimageurl;
        this.petname = petname;
        this.intro = intro;

    }


    public Pet(String petimageurl, String petname, String petbreed, String petweight, String birthday, String gender, String intro, String petid) {
        this.petimageurl = petimageurl;
        this.petname = petname;
        this.petbreed = petbreed;
        this.petweight = petweight;
        this.birthday = birthday;
        this.gender = gender;
        this.intro = intro;
        this.petid = petid;
    }


    public String getPetid() {
        return petid;
    }

    public void setPetid(String petid) {
        this.petid = petid;
    }

    public String getPetimagerul() {
        return petimageurl;
    }

    public void setPetimageurl(String petimage) {
        this.petimageurl = petimageurl;
    }

    public String getPetname() {
        return petname;
    }

    public void setPetname(String petname) {
        this.petname = petname;
    }

    public String getPetbreed() {
        return petbreed;
    }

    public void setPetbreed(String petbreed) {
        this.petbreed = petbreed;
    }

    public String getPetweight() {
        return petweight;
    }

    public void setPetweight(String petweight) {
        this.petweight = petweight;
    }

    public String getBirthday() {
        return birthday;
    }

    public void setBirthday(String birthday) {
        this.birthday = birthday;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public String getIntro() {
        return intro;
    }

    public void setIntro(String intro) {
        this.intro = intro;
    }
}

Ответы [ 4 ]

1 голос
/ 27 июня 2019

У вас есть опечатка в методе сеттера

public void setPetimageurl(String petimage) {
    this.petimageurl = petimageurl; // typo
}

Чтобы избежать такой ситуации, используйте @PropertyName с открытым полем и не используйте getter setter, а также не используйте @PropertyName с getter setter.

@PropertyName("petimageurl")
public String petimageurl;
1 голос
/ 27 июня 2019

У вас есть опечатка в setPetimageurl, замените ее на

public void setPetimageurl(String petimage) {
    this.petimageurl = petimage; // you must use petimage instead petimageurl to set the value petimage to the local variable petimageurl
}

Надеюсь, это решит вашу проблему!

1 голос
/ 27 июня 2019

Изменить это-

 public void setPetimageurl(String petimage) {
        this.petimageurl = petimageurl;
    }

to-

public void setPetimageurl(String petimageurl) {
        this.petimageurl = petimageurl;
    }
1 голос
/ 27 июня 2019
You are setting as this - 

 public void setPetimageurl(String petimage) {
        this.petimageurl = petimageurl;
    }

Make it - 

 public void setPetimageurl(String petimageurl) {
        this.petimageurl = petimageurl;
    }

Поменять петимаг на петимагурл

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...