如何修复 Android Kotlin 中未解决的 reference:imageView 错误?

时间:2021-08-01 09:16:31

标签: android-studio kotlin

我的 foodview.imageView.setImageResource(food.image!!) 有问题,错误未解决参考:imageView

override fun getView(index: Int, convertView: View?, parent: ViewGroup?): View {
        var food :Food = this.foodlist[index]
        var inflater :LayoutInflater = context!!.getSystemService(LAYOUT_INFLATER_SERVICE) as LayoutInflater
        var foodview = inflater.inflate(R.layout.mylayout,null)
        foodview.imageView.setImageResource(food.image!!)
        foodview.textView.text = food.name!!
        return foodview
    }

1 个答案:

答案 0 :(得分:0)

当您尝试使用 setImageResource() 设置图像时,您传递的参数必须是 int 例如。 setImageResource(R.drawable.image)。检查变量 food.image 的值