Images not showing in recyclerview from firebase

I’m trying to get images from firebase into a recyclerview but it doesn’t show up I have stored the download URL in a model class so I can retrieve it later

Here is the screen with no images in recyclerview enter image description here

here is the realtimedatabe screenshot enter image description here

and also the rules are true for realtimedatabase and storage

Java Files

Search_Fragment.java

 public class Search_Fragment extends Fragment {
    public List<Upload> mUploads;
    PostAdapter postsAdapter;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_search, container, false);
        RecyclerView postRecyclerView = view.findViewById(R.id.postRecyclerView);
        DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference("uploads");
        postRecyclerView.setLayoutManager(
                new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL)
        );
        mUploads = new ArrayList<>();
        postsAdapter = new PostAdapter(getContext(), mUploads);
        postRecyclerView.setAdapter(postsAdapter);

        //This are images that i tried manual ly and it worked fine
//        List<PostItem> postItems = new ArrayList<>();
//        postItems.add(new PostItem(R.drawable.image1));
//        postItems.add(new PostItem(R.drawable.image2));
//        postItems.add(new PostItem(R.drawable.image3));
//        postItems.add(new PostItem(R.drawable.image4));
//        postItems.add(new PostItem(R.drawable.image5));
//        postItems.add(new PostItem(R.drawable.image7));
        databaseReference.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(@NonNull DataSnapshot snapshot) {
                if (snapshot.exists()){
                    for (DataSnapshot dataSnapshot : snapshot.getChildren()) {
                        Upload upload = dataSnapshot.getValue(Upload.class);
                        Log.i("Sucess",upload.getmImageUrl());
                        mUploads.add(upload);

                }

                }
                else {
                    Toast.makeText(getContext(),"Failure",Toast.LENGTH_SHORT).show();
                }
                //notify the adapter
                postsAdapter.notifyDataSetChanged();
            }

            @Override
            public void onCancelled(@NonNull DatabaseError error) {
            }
        });
        return view;
    }
}

PostAdapter.Java //Apadter Class

public class PostAdapter extends RecyclerView.Adapter<PostAdapter.PostViewHolder> {
    public static List<Upload> mUploads;
    Context mcontext;


    public PostAdapter(Context context, List<Upload> uploads) {
        mUploads = uploads;
        mcontext = context;
    }


    @NonNull
    @Override
    public PostViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view;
        view = LayoutInflater.from(mcontext).inflate(R.layout.post_item_container, parent, false);
        return new PostViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull PostViewHolder holder, int position) {
        Upload uploadCurrent = mUploads.get(position);
        Transformation transformation = new RoundedTransformationBuilder()
                .borderColor(Color.WHITE)
                .borderWidthDp(5)
                .cornerRadiusDp(13)
                .oval(false)
                .build();
        Log.i("sucess",uploadCurrent.getmImageUrl());
        Picasso.get()
                .load(uploadCurrent.getmImageUrl())
                .fit()
                .transform(transformation)
                .into(holder.postImageView);


    }

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

    public static class PostViewHolder extends RecyclerView.ViewHolder {
        RoundedImageView postImageView;

        PostViewHolder(@NonNull View itemView) {
            super(itemView);
            postImageView = itemView.findViewById(R.id.imagePost);
        }

    }
}

Upload_Fragment.Java

public class Upload_Fragment extends Fragment {
    private static final int PICK_IMAGE_REQUEST = 10;
    private ImageView uploadImageView;
    private Uri mImageUri;
    private StorageReference storageReference;
    private DatabaseReference databaseReference;
    private StorageTask mUploadTask;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_upload, container, false);
        Button chooseImageButton = view.findViewById(R.id.upload_image_button);
        Button uploadImageButton = view.findViewById(R.id.done_button);
        uploadImageView = view.findViewById(R.id.upload_image_view);
        storageReference = FirebaseStorage.getInstance().getReference("uploads");
        databaseReference = FirebaseDatabase.getInstance().getReference("uploads");
        chooseImageButton.setOnClickListener(v -> openFileChooser());
        uploadImageButton.setOnClickListener(v -> {
            if (mUploadTask != null && mUploadTask.isInProgress()) {
                Toast.makeText(getActivity(), "Upload in Progress", Toast.LENGTH_SHORT).show();

            } else {
                uploadToFirebase(mImageUri);
            }


        });

        return view;
    }

    private void openFileChooser() {
        Intent intent = new Intent();
        intent.setType("image/*");
        intent.setAction(Intent.ACTION_GET_CONTENT);
        startActivityForResult(intent, PICK_IMAGE_REQUEST);
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK
                && data != null && data.getData() != null) {
            mImageUri = data.getData();
            Picasso.get().load(mImageUri).into(uploadImageView);

        }
    }

    private String getFileExtension(Uri uri) {

        ContentResolver contentResolver = Objects.requireNonNull(getActivity()).getContentResolver();
        MimeTypeMap mime = MimeTypeMap.getSingleton();
        return mime.getExtensionFromMimeType(contentResolver.getType(uri));
    }

    private void uploadToFirebase(Uri mImageUri) {
        if (mImageUri != null) {
            final ProgressDialog progressDialog = new ProgressDialog(getActivity());
            progressDialog.setTitle("Uploading...");
            progressDialog.show();

            StorageReference reference = storageReference.child(System.currentTimeMillis()
                    + "." + getFileExtension(mImageUri));
            reference.putFile(mImageUri)
                    .addOnSuccessListener(taskSnapshot -> {
                        progressDialog.dismiss();
                        Toast.makeText(getActivity(), "Saved Succesfully", Toast.LENGTH_SHORT).show();
                        reference.getDownloadUrl()
                                .addOnSuccessListener(uri -> {
                                    Upload upload = new Upload(uri.toString());
                                    String uploadId = databaseReference.push().getKey();
                                    databaseReference.child(uploadId).setValue(upload);
                                    Log.i("Link", uri.toString());
                                });
                    })
                    .addOnProgressListener(snapshot -> {
                        double progress = (100.0 * snapshot.getBytesTransferred() / snapshot
                                .getTotalByteCount());
                        progressDialog.setMessage("Uploaded " + (int) progress + "%");
                    })
                    .addOnFailureListener(e -> {
                        progressDialog.dismiss();
                        Toast.makeText(getActivity(), "Error Ocurred" + e.getMessage(), Toast.LENGTH_SHORT).show();
                    });


        }
    }
}

Upload.Java //Model class

public class Upload {
    private String mImageUrl;


    public Upload() {

    }

    public Upload(String imageUrl) {
        this.mImageUrl = imageUrl;
    }

    public String getmImageUrl() {
        return mImageUrl;
    }

    public void setmImageUrl(String mImageUrl) {
        this.mImageUrl = mImageUrl;
    }
}

Answer

See to resolve your issue it needs to be debug few things then and then only you will able to resolve the issue.Also you need to clarify at which point what happen.You can try below things to get solution.

1..Put Log or Toast inside for loop while adding url to the mUploads list.Like toasting upload.getmImageUrl() and check is it giving you right http image url or not.

2.Put Log or Toast before the loading image url by Picasso.Like toasting uploadCurrent.getmImageUrl() and check is it giving you right http image url or not.

If error occuerd while toasting this put toString(); at the end. After that you will get better idea to resolve the issue.

EDIT: In above all case if you are getting right url then the problem is with Picasso library.You can try Glide to load the image.For that add

implementation 'com.github.bumptech.glide:glide:4.12.0'

annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'

and then in side onBindViewHolder load image like this.

Glide.with(mContext).load(uploadCurrent.getmImageUrl()).into(holder.postImageView);