0
votes

Firebase Data Picture

Model

 private String name,rating,ImageUrl,description,maxminutes,minorder,minquaninty;

    public Try_Model() {

    }
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getRating() {
        return rating;
    }

    public void setRating(String rating) {
        this.rating = rating;
    }

    public String getImageUrl() {
        return ImageUrl;
    }

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

    public String getDescription() {
        return description;
    }

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

    public String getMaxminutes() {
        return maxminutes;
    }

    public void setMaxminutes(String maxminutes) {
        this.maxminutes = maxminutes;
    }

    public String getMinorder() {
        return minorder;
    }

    public void setMinorder(String minorder) {
        this.minorder = minorder;
    }

    public String getMinquaninty() {
        return minquaninty;
    }

    public void setMinquaninty(String minquaninty) {
        this.minquaninty = minquaninty;
    }
}

MainActivity

    mRecycleriew =findViewById(R.id.my_recycler_view);
    mRecycleriew.setLayoutManager(new LinearLayoutManager(this));



    mFirebaseDatabase=FirebaseDatabase.getInstance();
    mRef=mFirebaseDatabase.getReference().child("restaurants");


}


protected void onStart() {

    super.onStart();
    FirebaseRecyclerAdapter<Try_Model,ViewHolders>firebaseRecyclerAdapter=
            new FirebaseRecyclerAdapter<Try_Model, ViewHolders>(
                    Try_Model.class,
                    R.layout.shop_name_list,
                    ViewHolders.class,
                    mRef)
            {
                @Override
                protected void populateViewHolder(ViewHolders viewHolder, Try_Model model, int position) {


                    viewHolder.setDetails(getApplicationContext(),model.getName(),model.getDescription(),model.getImageUrl(),model.getMaxminutes(),model.getMinorder(),model.getMinquaninty(),model.getRating());

                }
            };
           mRecycleriew.setAdapter(firebaseRecyclerAdapter);
}

ViewHolders

 View mView;

public ViewHolders(View itemView) {

    super(itemView);
    mView=itemView;
}
String name,rating,ImageUrl,description,maxminutes,minorder,minquaninty;
public  void setDetails(Context ctx, String modelName, String name, String description, String ImageUrl, String maxminutes, String minorder, String minquaninty){

    TextView mName=mView.findViewById(R.id.shopTitle);
    TextView mRating=mView.findViewById(R.id.shoprating);
    TextView mDescription=mView.findViewById(R.id.shopdescrpt);
    TextView mMinorder=mView.findViewById(R.id.shopminorder);
    TextView mMaxminutes=mView.findViewById(R.id.shopmaxminutes);
    TextView mMaxQuantity=mView.findViewById(R.id.shopquantityperperson);
    ImageView mImageView = mView.findViewById(R.id.shopimageView);


    mName.setText(name);
    mDescription.setText(description);
    mMaxminutes.setText(maxminutes);
    mMinorder.setText(minorder);
    mMaxQuantity.setText(minquaninty);
    mRating.setText(rating);
    Picasso.with(mView.getContext()).load(ImageUrl).placeholder( R.drawable.progress_animation ).into(mImageView);

}

Error Details

com.google.firebase.database.DatabaseException: Failed to convert value of type java.lang.Long to String at com.google.android.gms.internal.firebase_database.zzkt.zzb(Unknown Source) at com.google.android.gms.internal.firebase_database.zzkt.zza(Unknown Source) at com.google.android.gms.internal.firebase_database.zzkt.zzb(Unknown Source) at com.google.android.gms.internal.firebase_database.zzku.zza(Unknown Source) at com.google.android.gms.internal.firebase_database.zzkt.zzb(Unknown Source) at com.google.android.gms.internal.firebase_database.zzkt.zza(Unknown Source) at com.google.firebase.database.DataSnapshot.getValue(Unknown Source) at com.firebase.ui.database.FirebaseRecyclerAdapter.parseSnapshot(FirebaseRecyclerAdapter.java:151) at com.firebase.ui.database.FirebaseRecyclerAdapter.getItem(FirebaseRecyclerAdapter.java:140) at com.firebase.ui.database.FirebaseRecyclerAdapter.onBindViewHolder(FirebaseRecyclerAdapter.java:183) at android.support.v7.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:6673) at android.support.v7.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:6714) at android.support.v7.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline(RecyclerView.java:5647) at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5913) at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5752) at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5748) at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2232) at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1559) at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1519) at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:614) at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3812) at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3529) at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:4082) at android.view.View.layout(View.java:16653) at android.view.ViewGroup.layout(ViewGroup.java:5438) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1743) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1586) at android.widget.LinearLayout.onLayout(LinearLayout.java:1495) at android.view.View.layout(View.java:16653)

2

2 Answers

2
votes

Your values for the rating property are stored as a number, but your code declares them as a string. To fix the

private String name,ImageUrl,description,maxminutes,minorder,minquaninty;
private Double rating;

public Try_Model() {

}
public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public Double getRating() {
    return rating;
}

public void setRating(Double rating) {
    this.rating = rating;
}
...
0
votes

The error is right there on the first line of the error log

com.google.firebase.database.DatabaseException: Failed to convert value of type java.lang.Long to String

Try changing this mRating.setText(rating); to this mRating.setText(rating.toString()); or this mRating.setText(String.valueOf(rating));

and also change the datatype of rating in the model class to double or Double.

and lets see the result