سلام من کدی که استاد نوشتن رو نوشتم اما حلقه froEach بدون هیچ دلیلی باعث اکسپشن میشه و دلیلش رو نتونستم پیدا کنم
کد اداپتر
package com.alireza.nikeiran.feature.order
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.alireza.nikeiran.R
import com.alireza.nikeiran.comman.convertToPixel
import com.alireza.nikeiran.comman.formatPrice
import com.alireza.nikeiran.data.source.orderHistory.OrderItemHistory
import com.alireza.nikeiran.view.NikeImageView
class OrderHistoryItemAdapter(val context: Context ,val orderItems : List) : RecyclerView.Adapter() {
val layoutParam : LinearLayout.LayoutParams
init {
val size = convertToPixel(100f,context).toInt()
val margin = convertToPixel(8f,context).toInt()
layoutParam = LinearLayout.LayoutParams(size,size)
layoutParam.setMargins(margin,0,margin,0)
}
inner class OrderItemViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView){
val orderItemId = itemView.findViewById(R.id.orderItemId)
val orderItemPrice = itemView.findViewById(R.id.orderItemPrice)
val orderProductsLl = itemView.findViewById(R.id.orderProductsLl)
val nikeImageView = NikeImageView(context)
fun bind (orderItemHistory: OrderItemHistory){
orderItemId.text = orderItemHistory.id.toString()
orderItemPrice.text = formatPrice(orderItemHistory.payable)
orderProductsLl.removeAllViews()
orderItemHistory.product_order_item.forEach {
////////////// error is here
}
}
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): OrderItemViewHolder {
return OrderItemViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.order_history_item,parent,false))
}
override fun onBindViewHolder(holder: OrderItemViewHolder, position: Int) = holder.bind(orderItems[position])
override fun getItemCount(): Int = orderItems.size
}