пытается получить данные пользователей - PullRequest
1 голос
/ 06 мая 2020

Я пытаюсь получить другие данные, которые сохранили пользователи, такие как их сообщение, изображение, которое они загружают, описание и имя своего сообщения, и отобразить их в режиме повторного просмотра. Вся эта информация сохраняется в папке со случайным ключом. Когда я пытаюсь получить все, ничего не отображается, кроме пустого представления карты плюс, я замечаю, что получаю эти три предупреждающих сообщения 2020-05-06 11:19:50.473 11745-11745/com.myapp.jappy W/ClassMapper: No setter/field for firstname found on class com.myapp.jappy.UserInformation 2020-05-06 11:19:50.474 11745-11745/com.myapp.jappy W/ClassMapper: No setter/field for email found on class com.myapp.jappy.UserInformation 2020-05-06 11:19:50.474 11745-11745/com.myapp.jappy W/ClassMapper: No setter/field for lastname found on class com.myapp.jappy.UserInformation, но я не пытаюсь получить адрес электронной почты, имя и фамилию пользователей. Их что-то не так, как все спасается, или что? enter image description here Может ли кто-нибудь помочь мне решить эту проблему. Заранее спасибо.

//Model 

public class Upload {
    private String ImageUrl;
    private String post;
    private String post_name;
    private String description;


    public Upload(String imageUrl, String postname, String postt, String descrip) {
        ImageUrl = imageUrl;
        post = postt;
        post_name = postname;
        description = descrip;




    }

    //Empty constructor needed
    public Upload() {


    }


    public String getImageUrl() {
        return ImageUrl;
    }

    public void setImageUrl(String imageUrl) {
        ImageUrl = imageUrl;
    }

    public String getPost() {
        return post;
    }

    public void setPost(String post) {
        this.post = post;
    }

    public String getPost_name() {
        return post_name;
    }

    public void setPost_name(String post_name) {
        this.post_name = post_name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }
}


 //Adapter class

  public class ImageAdapter extends RecyclerView.Adapter<ImageAdapter.ImageViewHolder>{

    private Context mContext;
    private ArrayList<Upload> users;

    public ImageAdapter(Context context, ArrayList<Upload> uploads){
is        mContext = context;
        users = uploads;

    }

    @NonNull
    @Override
    public ImageViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View V = LayoutInflater.from(mContext).inflate(R.layout.cardview, parent, false);
        return new ImageViewHolder(V);


    }

    @Override
    public void onBindViewHolder(@NonNull ImageViewHolder holder, int position) {
        //String uploadCurrent=users.get(position).getmImageUrl();

        holder.txt1.setText(users.get(position).getDescription());
        Picasso.get().load(users.get(position).getmImageUrl()).fit().centerCrop().into(holder.imageView);

    }

    @Override
    public int getItemCount() {
        return users.size();

    }

    public class ImageViewHolder extends RecyclerView.ViewHolder{
        public ImageView imageView;
        public TextView txt1;

        public ImageViewHolder(@NonNull View itemView) {
            super(itemView);

            imageView=itemView.findViewById(R.id.imageview);
            txt1=itemView.findViewById(R.id.action);
        }
    }
}


//Profile page 

  recyclerView = findViewById(R.id.recyclerView);
        RecyclerView.LayoutManager layoutManager = new GridLayoutManager(getApplicationContext(),3);

        recyclerView.setLayoutManager(layoutManager);
        myUploads = new ArrayList<UserInformation>();
        aAdapter = new ImageAdapter(ProfileActivity.this, myUploads);
        recyclerView.setAdapter(aAdapter);
        aAdapter.notifyDataSetChanged();









        databaseReference = FirebaseDatabase.getInstance().getReference("Users");
       String uid = FirebaseAuth.getInstance().getCurrentUser().getUid();

        firebaseStorage = FirebaseStorage.getInstance();
        storageReference = firebaseStorage.getReference();

        firebaseUser = firebaseAuth.getInstance().getCurrentUser();
        t=findViewById(R.id.none);

        //getSupportFragmentManager().beginTransaction().replace(R.id.frameLayout,firstFragment);









            databaseReference.child(uid).addListenerForSingleValueEvent(new ValueEventListener() {
                @Override
                public void onDataChange(@NonNull DataSnapshot dataSnapshot) {



                    UserInformation upload = dataSnapshot.getValue(UserInformation.class);

                    myUploads.add(upload);
                    aAdapter = new ImageAdapter(ProfileActivity.this, myUploads);
                    recyclerView.setAdapter(aAdapter);



                    aAdapter.notifyDataSetChanged();







                }

                @Override
                public void onCancelled(@NonNull DatabaseError databaseError) {
                    Toast.makeText(ProfileActivity.this, databaseError.getMessage(), Toast.LENGTH_LONG).show();

                }
            });

1 Ответ

0 голосов
/ 06 мая 2020

Ваш Users Node должен выглядеть так:

Users
|
|------UID
       |
        _____email
        _____firstname
        _____lastname

|------UID2
       ..........
       ..........
       ..........

Теперь вы должны добавить новый узел для posts:

Upload
|
|------randomID

       |_____ImageUrl
        _____description
        _____post
        _____post_name


|------randomID2
       ..........
       ..........
       ..........

Создайте класс Users:

public class Users {

//add these
private String email;
private String firstname;
private String lastname;

//constrcutor becomes

public Upload(String email, String firstname, String lastname) {

    this.email = email;
    this.firstname = firstname;
    this.lastname = lastname;


}

//also create getters and setters for email , firstname , lastname..........

Ваш Upload класс будет выглядеть так:

public class Upload {

private String ImageUrl;
private String post;
private String post_name;
private String description;


//constrcutor 

public Upload(String imageUrl, String postname, String postt, String descrip) {
    ImageUrl = imageUrl;
    post = postt;
    post_name = postname;
    description = descrip;


}



//also create getters and setters for all the fields
...