Reputation:
I am using firebase storage to store images and firebase firestore to store data and image url of the storage.
I am getting the following error while downloading the image
java.io.IOException: { "error": { "code": 404, "message": "Not Found. Could not get object", "status": "GET_OBJECT" }}
Below is the postAdapter class which is then used in the fragment to retrieve the list.
Please let me know where I am going wrong in this.
public class PostsAdapter extends FirestoreRecyclerAdapter<PostsModel, PostsAdapter.PostsHolder> {
private OnItemClickListener listener;
private View.OnClickListener buttonListener;
private Context mContext;
private String id;
//boolean likechecker = false;
private static final String TAG = "DocSnippets";
StorageReference storageReference = FirebaseStorage.getInstance().getReference().child("profile_pic");
public PostsAdapter(@NonNull FirestoreRecyclerOptions<PostsModel> options) {
super(options);
}
@Override
protected void onBindViewHolder(@NonNull final PostsHolder holder, int position, @NonNull final PostsModel model) {
//retrieve the fields here
final String documentId = getSnapshots().getSnapshot(position).getId();
holder.textViewDescription.setText(model.getPostContent());
holder.textViewSpinnerC.setText(model.getPost_author_spinnerC());
holder.textViewCategory.setText(model.getPostcategory());
holder.textViewTitle.setText(model.getPostTitle());
holder.textViewPostUsername.setText(model.getPost_author_username());
storageReference.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
// Got the download URL for 'users/me/profile.png'
holder.postUserImage.setImageURI(uri);
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
// Handle any errors
}
});
holder.commentsbutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent toCommentActivity = new Intent(view.getContext(), CommentActivity.class);
toCommentActivity.putExtra("PostKey", documentId);
view.getContext().startActivity(toCommentActivity);
}
}); }
@NonNull
@Override
public PostsHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.post_list_layout,
parent, false);
return new PostsHolder(v);
}
public void deleteItem(int position) {
getSnapshots().getSnapshot(position).getReference().delete();
}
public void setOnClickListener(OnClickListener postKey) {
}
class PostsHolder extends RecyclerView.ViewHolder {
TextView textViewTitle;
TextView textViewDescription;
TextView textViewSpinnerC;
TextView textViewCategory;
TextView textViewPostUsername;
TextView textViewTime;
CircleImageView postUserImage;
ImageButton favPostButton;
Button commentsbutton;
public PostsHolder(final View itemView) {
super(itemView);
textViewTitle = itemView.findViewById(R.id.post_item_title);
textViewDescription = itemView.findViewById(R.id.post_item_description);
textViewTime = itemView.findViewById(R.id.post_item_time);
commentsbutton = itemView.findViewById(R.id.commenting_button);
favPostButton = itemView.findViewById(R.id.imageButton1);
textViewSpinnerC = itemView.findViewById(R.id.post_item_SpinnerC);
textViewCategory = itemView.findViewById(R.id.post_item_Category);
postUserImage = itemView.findViewById(R.id.post_user_profile_image);
textViewPostUsername = itemView.findViewById(R.id.post_item_username);
itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int position = getAdapterPosition();
if (position != RecyclerView.NO_POSITION && listener != null) {
listener.onItemClick(getSnapshots().getSnapshot(position), position);
}
}
});
}
}
public interface OnClickListener
{
void OnClickListener(DocumentSnapshot documentSnapshot, int position);
}
public void setOnClickListener(View.OnClickListener onClickListener) {
this.buttonListener = onClickListener;
}
public interface OnItemClickListener {
void onItemClick(DocumentSnapshot documentSnapshot, int position);
}
public void setOnItemClickListener(OnItemClickListener listener) {
this.listener = listener;
}
}
Upvotes: 2
Views: 482
Reputation: 6919
You have provided the user profile image url in Database. Try using picasso
Picasso.get().load(model.getPost_user_profile_pic_url()).into(holder.postUserImage);
Upvotes: 1