我在为一个图像和两个textview设置recylerview时遇到错误
我不是错误的意思。我已经阅读了一些文档,但找不到正确的文档。我在H​​older类中提到了以下错误行

一个小的帮助将是巨大的。谢谢!

适配器类:

public class SlipAdapter extends RecyclerView.Adapter<SlipDataHolder> {

    private List<StringList> slipList;

    public SlipAdapter(){
        slipList=new ArrayList<>();
        slipList.add(new StringList("Slip-1","100$/day",R.drawable.table));
        slipList.add(new StringList("Slip-2","200$/day",R.drawable.tablenew));
        slipList.add(new StringList("Slip-3","300$/day",R.drawable.table));
        slipList.add(new StringList("Slip-4","400$/day",R.drawable.tablenew));
        slipList.add(new StringList("Slip-5","1500$/day",R.drawable.table));
        slipList.add(new StringList("Slip-6","600$/day",R.drawable.tablenew));
        slipList.add(new StringList("Slip-7","700$/day",R.drawable.table));
        slipList.add(new StringList("Slip-8","800$/day",R.drawable.tablenew));
        slipList.add(new StringList("Slip-9","900$/day",R.drawable.table));
        slipList.add(new StringList("Slip-10","1000$/day",R.drawable.tablenew));

    }

    @Override
    public SlipDataHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        Context context =parent.getContext();
        LayoutInflater inflater=(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view=inflater.inflate(R.layout.layout_slip,parent,false);
        return new SlipDataHolder(view);

    }

    @Override
    public void onBindViewHolder(SlipDataHolder holder, int position) {

        StringList s=slipList.get(position);
        holder.bindSlip(s);}

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


持有人类别:

public class SlipDataHolder extends RecyclerView.ViewHolder {

    private TextView nameOfSlip;
    private TextView priceOfSlip;
    private ImageView slipImage;

    public SlipDataHolder(View itemView) {
        super(itemView);

        nameOfSlip=(TextView) itemView.findViewById(R.id.name_of_slip);
        priceOfSlip=(TextView) itemView.findViewById(R.id.rate_of_slip);
        slipImage=(ImageView) itemView.findViewById(R.id.image_slip);
    }

    public void bindSlip(StringList stringList) {
        nameOfSlip.setText(stringList.stringSlipName);
        priceOfSlip.setText(stringList.stringPrice);
        slipImage.setImageResource(stringList.stringImage); //error line
    }
}


名称类别:

public class StringList {
    public String stringSlipName;
    public String stringPrice;
    public int stringImage;

    public StringList(String stringSlipName, String stringPrice, int stringImage) {
        this.stringImage = stringImage;
        this.stringPrice = stringPrice;
        this.stringSlipName = stringSlipName;
    }

}


Logcat:

java.lang.OutOfMemoryError: Failed to allocate a 132710412 byte allocation with 4194208 free bytes and 46MB until OOM
                      at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
                      at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)

最佳答案

通过减少所有图像的大小,我消除了我的错误!

07-27 17:08