title: Android Kotlin: Unresolved reference
body: <p>I'm trying setup an adapter using MainAdapter.kt inside my NewsFragment.kt but I get Unresolved reference. It will be nice if there is a solution to this problem. I'm new to Kotlin and would like your help. Much appreciated.</p>
  
  <p>2 errors:
  Unresolved reference: runOnUiThread.
  Unresolved reference: homeFeed.</p>
  
  <pre><code>runOnUiThread {
  worldnews.adapter = MainAdapter(homeFeed)
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/RpzBd.png" rel="nofollow noreferrer">enter image description here</a></p>
  
  <p>NewsFragment.kt</p>
  
  <pre><code>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 com.example.inprogress.R
  import com.google.gson.GsonBuilder
  import controller.MainAdapter
  import kotlinx.android.synthetic.main.fragment_news.*
  import kotlinx.android.synthetic.main.fragment_news.view.*
  import okhttp3.*
  import java.io.IOException
  
  class NewsFragment : Fragment() {
      // TODO: Rename and change types of parameters
      private var param1: String? = null
      private var param2: String? = null
  
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          arguments?.let {
              param1 = it.getString(ARG_PARAM1)
              param2 = it.getString(ARG_PARAM2)
          }
  
          fetchJson()
  
      }
  
      fun fetchJson() {
  
          val url = "https://api.letsbuildthatapp.com/youtube/home_feed"
  
          val request = Request.Builder().url(url).build()
  
          val client = OkHttpClient()
          client.newCall(request).enqueue(object: Callback {
              override fun onResponse(call: Call, response: Response) {
                  val body = response?.body()?.string()
                  println(body)
  
                  val gson = GsonBuilder().create()
                  gson.fromJson(body, HomeFeed::class.java)
  
                  runOnUiThread {
                  worldnews.adapter = MainAdapter(homeFeed)
                  }
  
                  println("Execution success!")
              }
              override fun onFailure(call: Call, e: IOException) {
                  println("Execution failed!")
              }
          })
  
      }
  
      override fun onCreateView(
          inflater: LayoutInflater, container: ViewGroup?,
          savedInstanceState: Bundle?
      ): View? {
          val view = inflater.inflate(R.layout.fragment_news, container, false)
  
          view.worldnews.layoutManager = LinearLayoutManager(activity)
  
          return view
      }
  
      companion object {
          /**
           * Use this factory method to create a new instance of
           * this fragment using the provided parameters.
           *
           * @param param1 Parameter 1.
           * @param param2 Parameter 2.
           * @return A new instance of fragment NewsFragment.
           */
          // TODO: Rename and change types and number of parameters
          @JvmStatic
          fun newInstance(param1: String, param2: String) =
              NewsFragment().apply {
                  arguments = Bundle().apply {
                      putString(ARG_PARAM1, param1)
                      putString(ARG_PARAM2, param2)
                  }
              }
      }
  }
  
  class HomeFeed(val videos: List&lt;Video&gt;)
  
  class Video(val id: Int, val name: String, val link: String, val imageUrl: String,
              numberOfViews: Int, val channel: Channel)
  
  class Channel(val name: String, val profileImageUrl: String)
  </code></pre>
  
  <p>MainAdapter.kt</p>
  
  <pre><code>import android.view.LayoutInflater
  import android.view.View
  import android.view.ViewGroup
  import androidx.recyclerview.widget.RecyclerView
  import com.example.inprogress.R
  import kotlinx.android.synthetic.main.list_row.view.*
  import view.HomeFeed
  
  class MainAdapter(val homeFeed: HomeFeed): RecyclerView.Adapter&lt;MainAdapter.ViewHolder&gt;() {
  
      override fun getItemCount(): Int {
  
          return homeFeed.videos.count()
      }
  
      override fun onCreateViewHolder(parent: ViewGroup, position: Int): ViewHolder {
          val layoutInflater = LayoutInflater.from(parent?.context)
          val cellForRow = layoutInflater.inflate(R.layout.list_row, parent, false)
          return ViewHolder(cellForRow)
      }
  
      override fun onBindViewHolder(holder: ViewHolder, position: Int) {
          val video = homeFeed.videos.get(position)
          holder.view.title.text = video.name
      }
  
      class ViewHolder(val view: View): RecyclerView.ViewHolder(view) {
  
      }
  
  }
  </code></pre>