0
設置一個圖像和兩個文本視圖的recylerview時出現錯誤 我不是錯誤的含義。我已閱讀一些文件,但我找不到合適的one.i已提及持有人類別下面的錯誤行設置活動中的reclerview時的字節分配問題
小幫助將是偉大的。謝謝!
適配器類:
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();}}
Holder類:
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)
這些圖像有多大?在哪個文件夾中,你放了它們? –