title: kotlin.UninitializedPropertyAccessException - lateinit property mAdapter has not been initialized - Android Development
body: <p>I am making a news app in android but I am getting error when I call a API(http) from my app. I don't know why the error is coming I implemented all the class, memebers, function.
  Pleas help me.</p>
  <p><strong>Here is the error description</strong></p>
  <pre><code>2021-01-21 09:21:25.896 18052-18052/com.arne.khabriapp E/AndroidRuntime: FATAL EXCEPTION: main
  Process: com.arne.khabriapp, PID: 18052
  java.lang.RuntimeException: Unable to start activity ComponentInfo{com.arne.khabriapp/com.arne.khabriapp.MainActivity}: kotlin.UninitializedPropertyAccessException: lateinit property mAdapter has not been initialized
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3270)
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
      at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
      at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
      at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
      at android.os.Handler.dispatchMessage(Handler.java:107)
      at android.os.Looper.loop(Looper.java:214)
      at android.app.ActivityThread.main(ActivityThread.java:7356)
      at java.lang.reflect.Method.invoke(Native Method)
      at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
   Caused by: kotlin.UninitializedPropertyAccessException: lateinit property mAdapter has not been initialized
      at com.arne.khabriapp.MainActivity.onCreate(MainActivity.kt:25)
      at android.app.Activity.performCreate(Activity.java:7802)
      at android.app.Activity.performCreate(Activity.java:7791)
      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1299)
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245)
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409) 
      at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83) 
      at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
      at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016) 
      at android.os.Handler.dispatchMessage(Handler.java:107) 
      at android.os.Looper.loop(Looper.java:214) 
      at android.app.ActivityThread.main(ActivityThread.java:7356) 
      at java.lang.reflect.Method.invoke(Native Method) 
      at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) 
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930) 
  2021-01-21 09:21:25.912 18052-18090/com.arne.khabriapp D/NetworkSecurityConfig: 
  No Network Security Config specified, using platform default
  </code></pre>
  <p><strong>Here is my MainActivity.kt</strong></p>
  <pre><code>    package com.arne.khabriapp
  
  import androidx.appcompat.app.AppCompatActivity
  import android.os.Bundle
  import android.widget.Toast
  import androidx.recyclerview.widget.LinearLayoutManager
  import androidx.recyclerview.widget.RecyclerView
  import com.android.volley.Request
  import com.android.volley.toolbox.JsonObjectRequest
  
  
  class MainActivity : AppCompatActivity(), NewsItemClicked {
  
      private lateinit var  mAdapter: NewsListAdapter
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          setContentView(R.layout.activity_main)
  
          val recyclerView = findViewById&lt;RecyclerView&gt;(R.id.rView)
          recyclerView.layoutManager  = LinearLayoutManager(this)
  //        recyclerView.layoutManager  = GridLayoutManager(this,12)
  //        recyclerView.layoutManager   = StaggeredGridLayoutManager(15,12)
           fetchData()
  
          recyclerView.adapter = mAdapter
  
  
      }
  
      private fun fetchData() {
  //        val list = ArrayList&lt;String&gt;()
  //        for(i in 0 until 100){
  //            list.add(&quot;item $i&quot;)
  //        }
  //        return list
          val url = &quot;https://newsapi.org/v2/top-headlines?country=in&amp;apiKey=9bb7bf6152d147ad8ba14cd0e7452f2f&quot;
          val jsonObjectRequest = JsonObjectRequest(
              Request.Method.GET,
              url,
              null,
              {
                  val newsJsonArray = it.getJSONArray(&quot;articles&quot;)
                  val newsArray = ArrayList&lt;NewsClass&gt;()
                  for (i in 0 until newsJsonArray.length()){
                      val newsJsonObject = newsJsonArray.getJSONObject(i)
                      val news =NewsClass(
                          newsJsonObject.getString(&quot;title&quot;),
                          newsJsonObject.getString(&quot;author&quot;),
                          newsJsonObject.getString(&quot;url&quot;),
                          newsJsonObject.getString(&quot;urlToImage&quot;)
                      )
                      newsArray.add(news)
                  }
                  mAdapter.updateNews(newsArray)
              },
              {
  
              }
  
          )
          MySingletonClass.getInstance(this).addRequestQueue(jsonObjectRequest)
  
      }
  
      override fun OnItemClick(item: NewsClass) {
  
      }
  }   
  </code></pre>
  <p><strong>Here is my NewsAdapter.kt</strong></p>
  <pre><code>package com.arne.khabriapp
  
  import android.view.LayoutInflater
  import android.view.View
  import android.view.ViewGroup
  import android.widget.TextView
  import androidx.recyclerview.widget.RecyclerView
  
  //class Name: extendItForRecyclerView.Adapter&lt;ViewHolderClass&gt;
  class NewsListAdapter( private val listener: NewsItemClicked): RecyclerView.Adapter&lt;NewsViewHolder&gt;()
  {
  
      private val items: ArrayList&lt;NewsClass&gt; = ArrayList()
  //    call me when each time one viewholder is created
      override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): NewsViewHolder {
  
      //Layout Inflater  - Converts XML into View
      val view = LayoutInflater.from(parent.context).inflate(R.layout.itemnews, parent, false)
  
      val viewHolder = NewsViewHolder(view)
      view.setOnClickListener{
          //this is a call back to main activity so the main activity knows that any item is clicked and then the mainn activity behave according to this.
          listener.OnItemClick(items[viewHolder.adapterPosition])
          
      }
          return viewHolder
      }
  
      //    I will bind the item with viewholder
      override fun onBindViewHolder(holder: NewsViewHolder, position: Int) {
          val currentItem = items[position]
          holder.titleView.text = currentItem.title
      }
  
  
  //    call me only one time i will give you how many item will be here in list
      override fun getItemCount(): Int {
          return items.size
      }
  
      fun updateNews(updatedNews: ArrayList&lt;NewsClass&gt;){
          items.clear()
          items.addAll(updatedNews)
  
          notifyDataSetChanged()
      }
  }
  class NewsViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView){
      val titleView: TextView = itemView.findViewById(R.id.title)
  }
  
  interface NewsItemClicked{
      fun OnItemClick(item: NewsClass)
  }
  </code></pre>
  <p><em><strong>Please Give Some Answer</strong></em>
  <strong>Thank you very much in advanced</strong></p>