I am trying to access the image stored in the firebase storage but it does not show up in the app. Rather rest all details like product name, product description and the price are seen perfectly but the image is not shown and even there is no error in the Logcat.
I am a beginner in Android Studio.
This is my Java code-named "KeyChainActivity.java"
package com.example.giftngame;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.Toast;
import com.example.giftngame.Model.Products;
import com.example.giftngame.ViewHolder.ProductViewHolder;
import com.firebase.ui.database.FirebaseRecyclerAdapter;
import com.firebase.ui.database.FirebaseRecyclerOptions;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.squareup.picasso.Picasso;
public class KeyChainActivity extends AppCompatActivity
{
private DatabaseReference ProductsRef;
private RecyclerView recyclerView;
RecyclerView.LayoutManager layoutManager;
private String CategoryName;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_category);
CategoryName=getIntent().getExtras().get("category").toString().toString();
Toast.makeText(this,CategoryName,Toast.LENGTH_SHORT).show();
ProductsRef= FirebaseDatabase.getInstance().getReference().child("Products");
recyclerView=findViewById(R.id.recycler_menu);
recyclerView.setHasFixedSize(true);
layoutManager=new LinearLayoutManager(this);
recyclerView.setLayoutManager(layoutManager);
}
@Override
protected void onStart()
{
super.onStart();
FirebaseRecyclerOptions<Products> options=
new FirebaseRecyclerOptions.Builder<Products>()
.setQuery(ProductsRef,Products.class)
.build();
FirebaseRecyclerAdapter<Products, ProductViewHolder> adapter=
new FirebaseRecyclerAdapter<Products, ProductViewHolder>(options) {
@Override
protected void onBindViewHolder(@NonNull ProductViewHolder holder, int position, @NonNull Products model)
{
holder.txtProductName.setText(model.getPname());
holder.txtProductDescription.setText(model.getDescription());
holder.txtProductPrice.setText("Price= "+model.getPrice()+ " INR");
Picasso.get().load(model.getImage()).into(holder.imageView);
}
@NonNull
@Override
public ProductViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType)
{
View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.activity_key_chain,parent,false);
ProductViewHolder holder=new ProductViewHolder(view);
return holder;
}
};
recyclerView.setAdapter(adapter);
adapter.startListening();
}
}
This is another java code where I have declared the Firebase Database contents named "Products.java"
package com.example.giftngame.Model;
public class Products
{
private String pname,description,image,category,date,time;
private long pid,price;
public Products()
{
}
public Products(String pname, String description, long price, String image, String category, long pid, String date, String time)
{
this.pname = pname;
this.description = description;
this.price = price;
this.image = image;
this.category = category;
this.pid = pid;
this.date = date;
this.time = time;
}
public String getPname() {
return pname;
}
public void setPname(String pname) {
this.pname = pname;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public long getPrice() {
return price;
}
public void setPrice(long price) {
this.price = price;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
public String getCategory() {
return category;
}
public void setCategory(String category) {
this.category = category;
}
public long getPid() {
return pid;
}
public void setPid(long pid) {
this.pid = pid;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
}
There is nothing displayed in your view because your image
property does not hold a correct image URL. What you are storing:
gs://giftngame-ae160-appspot...
It is actually the location of your image in Firebase Storage and not the actual URL. To solve this, when you create a new object of your Products
class, pass the download URL of the image as explained in my answer from the following post: