Classifier 'User' does not have a companion object, and thus must be initialized here

I wish to add a profile image near every message sent in my group chat app. the image views are already present an everything is working well, but I don’t seem to get the logic in adding the image. What should I do? below is the code:

override fun onChildAdded(snapshot: DataSnapshot, previousChildName: String?) {
val chatMessage = snapshot.getValue(

            if (chatMessage != null) {
                chatMessage.let { Log.d(TAG, it.text) }

                if (chatMessage.fromId == FirebaseAuth.getInstance().uid) {
                    adapter.add(ChatToItem(chatMessage.text, user = User))
                }else {



I am getting the error at the level of user = User.

or in other words can someone guide me add the images? :pray:

one more thing is that I am trying to use picasso

What are you trying to do in the line with user = User? What do you think User means there?

This is the other code related : `

> //Load user chat in chatroom
> class ChatToItem(val text: String, val user: User): Item<GroupieViewHolder>() {
>     override fun bind(groupieViewHolder: GroupieViewHolder, position: Int) {
>         groupieViewHolder.itemView.idMessageTo.text = text
    //load our user image into the imageView of the chatmessage bubble..
    val uri = user.profileImageUrl
    val targetImageView = groupieViewHolder.itemView.idUserImageTo

Sorry that I can’t really say much about it, but I want to get an image from my firebase database and cache it using picasso, then pass it to the imageView in my chatlog. If you still can explicitly get my point please guide me on how to go around it maybe another way Sir. I am kinda new in the stuff :pray:

The ChatToItem() primary constructor expects an instance of User as its user parameter. But in the error line, User is not an instance — it’s the class name.

(That could still work if User had a companion object which was itself an instance of User — a very unlikely situation, but possible. However, in this case User doesn’t have a companion object, and so the code makes no sense, hence the error message.)

To fix it, change the User in that line to an instance of User.

It’s not clear from the code you’ve posted where you should get that instance, as there’s no other sign of one. Android may provide a way to get the current user — but I don’t know Android, so I can’t say.

Thanks gidds for your time taken to explain this. I am beginning to understand what is happening now. I’ll see how to get about it and if I still can’t, I hope giving you more details can permit you to guide me . :crossed_fingers:t2: