title: How to display data in RecyclerView using Retrofit2 API?
body: <p>First of all, I'm new to Android/Java/Kotlin development. I'm using Retrofit2 to retrieve data from Udacity API. I can see the response in the Logcat, but when I try to display it in RecyclerView there is just a blank screen. I think the error is in the MainActivity, but I'm still clueless and need help.</p>
  
  <p>My model classes</p>
  
  <pre><code>class Course(var title: String,
               var subtitle: String,
               var key: String,
               var instructors: List&lt;Instructor&gt;,
               var expected_learning: String,
               var required_knowledge: String)
  
  
  class Instructor(var name: String,
                   var bio: String)
  </code></pre>
  
  <p>My interface</p>
  
  <pre><code>interface ApiServiceInterface {
  
  @GET("courses")
  fun list() : Call&lt;UdacityCatalog&gt;
  
  }
  </code></pre>
  
  <p>My adapter</p>
  
  <pre><code>class CourseAdapter(val listCourses: ArrayList&lt;Course?&gt;, val context: Context) : RecyclerView.Adapter&lt;CourseAdapter.CourseViewHolder&gt;() {
  
      class CourseViewHolder(viewItem: View) : RecyclerView.ViewHolder(viewItem) { 
          val courseTitle = viewItem.findViewById&lt;TextView?&gt;(R.id.tv_title) as TextView 
          val courseSubtitle = viewItem.findViewById&lt;TextView?&gt;(R.id.tv_subtitle) as TextView 
          val courseKey = viewItem.findViewById&lt;TextView?&gt;(R.id.tv_course_key) as TextView 
          val instructorName = viewItem.findViewById&lt;TextView?&gt;(R.id.tv_instructor_name) as TextView 
      }
  
      override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): CourseViewHolder { 
          val viewHolder = LayoutInflater.from(parent?.context).inflate(R.layout.activity_item_list, parent, false) 
          val itemViewHolder = CourseViewHolder(viewHolder)
          return itemViewHolder
      }
  
      override fun onBindViewHolder(holder: CourseViewHolder?, position: Int) {
          holder?.courseTitle?.text = listCourses[position].title
          holder?.courseSubtitle?.text = listCourses[position].subtitle
          holder?.courseKey?.text = listCourses[position].key
          holder?.instructorName?.text = listCourses[position].instructors.toString() 
      }
  
      override fun getItemCount(): Int = listCourses.size
  
  }
  </code></pre>
  
  <p>My MainActivity -- I think the error is in here, but I haven't figured it out yet</p>
  
  <pre><code>class MainActivity : AppCompatActivity() {
  
      internal val TAG = "Testing Retrofit2 API"
      lateinit var mRecyclerView: RecyclerView
      lateinit var mCourseAdapter: RecyclerView.Adapter&lt;CourseAdapter.CourseViewHolder&gt;
      val listCourse = arrayListOf&lt;Course?&gt;()
  
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          setContentView(R.layout.activity_main_recyclerview)
  
          mRecyclerView = findViewById&lt;RecyclerView?&gt;(R.id.id_recycler_view) as RecyclerView
  
          val mLayoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
  
          mRecyclerView.layoutManager = mLayoutManager
  
          mRecyclerView.setHasFixedSize(true)
  
          mCourseAdapter = CourseAdapter(listCourse, applicationContext)
  
          mRecyclerView.adapter = mCourseAdapter
  
          mCourseAdapter.notifyDataSetChanged()
  
          val call = RetrofitInitializer().createService().list()
  
          call.enqueue(object : Callback&lt;UdacityCatalog&gt; {
  
              override fun onResponse(call: Call&lt;UdacityCatalog&gt;, response: Response&lt;UdacityCatalog&gt;) {
  
                  response.body()
  
                  if (!response.isSuccessful) {
                      Log.i(TAG, "[ ERROR ] " + response.code())
  
                  } else {
  
                      if (listCourse.isEmpty()) {
                          Toast.makeText(applicationContext, "Empty list!", Toast.LENGTH_LONG).show()
                      } else {
                          Toast.makeText(applicationContext, "Full list!", Toast.LENGTH_LONG).show()
                      }
  
                      val catalog = response.body()
  
                      for (c in catalog!!.courses!!) {
                          Log.i(TAG, String.format("%s: %s", c.title, c.subtitle, c.key, c.required_knowledge, c.expected_learning))
  
                          for (i in c.instructors!!) {
                              Log.i(TAG, i.name)
                          }
                          Log.i(TAG, "\n****************************************************************************************************\n")
                      }
                  }
              }
  
              override fun onFailure(call: Call&lt;UdacityCatalog&gt;?, t: Throwable?) {
                  Log.d(TAG, "onFailure() : " + t?.message)
              }
  
          })
  
      }
  
  }
  </code></pre>
  
  <p>An initializer class for Retrofit instance</p>
  
  <pre><code>class RetrofitInitializer {
  
      companion object Factory {
          val BASE_URL = "https://www.udacity.com/public-api/v0/"
      }
  
      private val retrofit = Retrofit.Builder()
              .baseUrl(BASE_URL)
              .addConverterFactory(GsonConverterFactory.create())
              .build()
  
      fun createService(): ApiServiceInterface = retrofit.create(ApiServiceInterface::class.java)
  
  }
  </code></pre>
  
  <p>My RecyclerView xml file</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:orientation="vertical"
      android:paddingBottom="16dp"
      android:paddingLeft="16dp"
      android:paddingRight="16dp"
      android:paddingTop="16dp"
      tools:context="activities.MainActivity"&gt;
  
      &lt;android.support.v7.widget.RecyclerView
          android:id="@+id/id_recycler_view"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:orientation="vertical"&gt;
  
      &lt;/android.support.v7.widget.RecyclerView&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>My CardView xml file</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;android.support.v7.widget.CardView 
  xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:layout_margin="16dp"
      android:orientation="vertical"&gt;
  
      &lt;LinearLayout
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="vertical"
          android:paddingBottom="16dp"
          android:paddingLeft="16dp"
          android:paddingRight="16dp"
          android:paddingTop="16dp"&gt;
  
          &lt;TextView
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:gravity="center"
              android:text="@string/udacity_catalog"
              android:textAppearance="?android:textAppearanceLarge"
              android:textColor="#9C27B0"
              android:textStyle="bold" /&gt;
  
          &lt;TextView
              android:id="@+id/tv_title"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layout_marginTop="20dp"
              android:gravity="start"
              android:hint="@string/hint_title"
              android:textAppearance="?android:textAppearanceMedium"
              android:textColor="#000000" /&gt;
  
          &lt;TextView
              android:id="@+id/tv_subtitle"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layout_marginTop="20dp"
              android:gravity="start"
              android:hint="@string/hint_subtitle"
              android:textAppearance="?android:textAppearanceMedium"
              android:textColor="#000000" /&gt;
  
          &lt;TextView
              android:id="@+id/tv_course_key"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layout_marginTop="20dp"
              android:gravity="start"
              android:hint="@string/hint_key"
              android:textAppearance="?android:textAppearanceMedium"
              android:textColor="#000000" /&gt;
  
          &lt;TextView
             android:id="@+id/tv_instructor_name"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:layout_marginTop="20dp"
             android:gravity="start"
             android:hint="@string/hint_name"
             android:textAppearance="?android:textAppearanceMedium"
             android:textColor="#000000" /&gt;
  
      &lt;/LinearLayout&gt;
  
  &lt;/android.support.v7.widget.CardView&gt;
  </code></pre>