Search code examples
androidandroid-studiokotlinpicasso

Getting Target Null Error message in Kotlin using Picasso


I am trying to display image using Json API but I am getting Target not null error message. I have three classes one main, adapter and model class. I have already added picasso library and the name is working fine without issue and image is an issue. Any help is appreciated.

Main Class:

var Test:String=catObj.getString("Test")
category.Test=Test
Picasso.get().load(category.Test).into(TestImage)---TestImage is my ImageView ID.

Adapter class:

class ViewHolder(itemView:View):RecyclerView.ViewHolder(itemView) {

    fun bindItem(Test:TestModel)
    {
        var name:TextView=itemView.findViewById<TextView>(R.id.CatName)
        var picture:TextView=itemView.findViewById<TextView>(R.id.CatImage)
        name.text=Test.name
        picture.text=Test.location

    }
}

Error Log:

  java.lang.IllegalArgumentException: Target must not be null.

Solution

  • Thanks Every one for their response. I solved it via below changes in my code.

    Main Class:

    var Test:String=catObj.getString("Test")
    category.Test=Test
    

    Adapter Class:

    class ViewHolder(itemView:View):RecyclerView.ViewHolder(itemView) {
    
        fun bindItem(Test:TestModel)
        {
            var name:TextView=itemView.findViewById<TextView>(R.id.CatName)
            var picture:ImageView=itemView.findViewById<ImageView>(R.id.CatImage)
            name.text=Test.name
            Picasso.get().load(category.picture).into(location)
        }
    }