title: com.google.firebase.database.DatabaseException: Can't convert object of type java.lang.String to type.1
body: <p>This problem arose to me when I responded to include the names of the users that I contacted. I want to include them in the list from the database, but the problem occurred as shown in the picture below the question.</p>
  <p><strong>the errors</strong></p>
  <pre><code>E/AndroidRuntime: FATAL EXCEPTION: main
  Process: com.hussainhasson.sayhi, PID: 21896
  com.google.firebase.database.DatabaseException: Can't convert object of type java.lang.String to type com.hussainhasson.sayhi.ModelClass.chatlist
      at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.convertBean(CustomClassMapper.java:436)
      at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.deserializeToClass(CustomClassMapper.java:232)
      at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.convertToCustomClass(CustomClassMapper.java:80)
      at com.google.firebase.database.DataSnapshot.getValue(DataSnapshot.java:203)
      at com.hussainhasson.sayhi.Fragments.chatFragment$onCreateView$1.onDataChange(chatFragment.kt:56)
      at com.google.firebase.database.core.ValueEventRegistration.fireEvent(ValueEventRegistration.java:75)
      at com.google.firebase.database.core.view.DataEvent.fire(DataEvent.java:63)
      at com.google.firebase.database.core.view.EventRaiser$1.run(EventRaiser.java:55)
      at android.os.Handler.handleCallback(Handler.java:873)
      at android.os.Handler.dispatchMessage(Handler.java:99)
      at android.os.Looper.loop(Looper.java:280)
      at android.app.ActivityThread.main(ActivityThread.java:6710)
      at java.lang.reflect.Method.invoke(Native Method)
      at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
  </code></pre>
  <hr />
  <h2>code fragment</h2>
  <p>This is the code for listening and parsing Firebase data</p>
  <pre class="lang-kotlin prettyprint-override"><code>package com.hussainhasson.sayhi.Fragments
  
  import android.os.Bundle
  import androidx.fragment.app.Fragment
  import android.view.LayoutInflater
  import android.view.View
  import android.view.ViewGroup
  import androidx.recyclerview.widget.LinearLayoutManager
  import androidx.recyclerview.widget.RecyclerView
  import com.google.firebase.auth.FirebaseAuth
  import com.google.firebase.auth.FirebaseUser
  import com.google.firebase.database.DataSnapshot
  import com.google.firebase.database.DatabaseError
  import com.google.firebase.database.FirebaseDatabase
  import com.google.firebase.database.ValueEventListener
  import com.hussainhasson.sayhi.AdappterClasses.UserAdappter
  import com.hussainhasson.sayhi.ModelClass.Users
  import com.hussainhasson.sayhi.ModelClass.chat
  import com.hussainhasson.sayhi.ModelClass.chatlist
  import com.hussainhasson.sayhi.R
  
  class chatFragment : Fragment()
  {
  
      private var userAdappter: UserAdappter?=null
      private var musers:List&lt;Users&gt;?=null
      private var userschatlist:List&lt;chatlist&gt;?=null
      lateinit var recycler_view_chatlist:RecyclerView
      private var firebaseUser:FirebaseUser?=null
  
  
      override fun onCreateView(
          inflater: LayoutInflater, container: ViewGroup?,
          savedInstanceState: Bundle?
      ): View? {
          // Inflate the layout for this fragment
         val view= inflater.inflate(R.layout.fragment_chat, container, false)
  
          recycler_view_chatlist=view.findViewById(R.id.recycler_view_chatlist)
          recycler_view_chatlist.setHasFixedSize(true)
          recycler_view_chatlist.layoutManager=LinearLayoutManager(context)
  
          firebaseUser=FirebaseAuth.getInstance().currentUser
          userschatlist=ArrayList()
          val ref=FirebaseDatabase.getInstance().reference
              .child(&quot;Chatlists&quot;).child(firebaseUser!!.uid)
  
  ref.addValueEventListener(object :ValueEventListener{
      override fun onDataChange(p0: DataSnapshot)
      {
  
          (userschatlist as ArrayList).clear()
              for (shot in p0.children)
              {
  
                      val chatlist1=shot.getValue(chatlist::class.java)
                      (userschatlist as ArrayList).add(chatlist1!!)
  
  
              }
  
          retrivechatlist()
  
      }
  
      override fun onCancelled(error: DatabaseError) {
  
      }
  
  
  })
          return view
      }
  
  private fun retrivechatlist()
  {
      musers=ArrayList()
      val ref=FirebaseDatabase.getInstance().reference.child(&quot;Users&quot;)
  
      ref.addValueEventListener(object :ValueEventListener{
          override fun onDataChange(p0: DataSnapshot) {
              (musers as ArrayList).clear()
              for (shot in p0.children)
              {
                  val user=shot.getValue(Users::class.java)
  
                  for (eachchatlist in userschatlist!!)
                  {
                      if (user!!.getUID().equals(eachchatlist.getid()))
                      {
                          (musers as ArrayList).add(user)
                      }
  
                  }
  
              }
              userAdappter= UserAdappter(context!!,(musers as ArrayList&lt;Users&gt;),true)
              recycler_view_chatlist.adapter=userAdappter
  
          }
  
          override fun onCancelled(error: DatabaseError) {
          }
  
      })
  
  }
  
  }
  </code></pre>
  <h2>code  class chatlists</h2>
  <p>Class that represents the structure of Firebase db data</p>
  <pre class="lang-kotlin prettyprint-override"><code>package com.hussainhasson.sayhi.ModelClass
  
  class chatlist
  {
      private var id:String=&quot;&quot;
  
      constructor()
      constructor(id: String) {
          this.id = id
      }
  
  
      fun getid ():String?
      {
          return id
      }
      fun setid (id : String)
      {
          this.id =id
      }
  }
  </code></pre>
  <p><a href="https://i.stack.imgur.com/DcrBU.png" rel="nofollow noreferrer">firebase database see image </a></p>