gpt4 book ai didi

android - 在 Activity 中设置 reclerview 时出现字节分配问题

转载 作者:行者123 更新时间:2023-11-30 00:38:17 26 4
gpt4 key购买 nike

我在为一个图像和两个 TextView 设置 recylerview 时出现错误我不知道错误是什么意思。我已经阅读了一些文档,但我找不到合适的文档。我在 holder 类中提到了下面的错误行

一个小的帮助会很棒。谢谢!

适配器类:

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;
}

}

日志:

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)

最佳答案

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

关于android - 在 Activity 中设置 reclerview 时出现字节分配问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43035045/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com