Variable not updated after lateinit declaraton, unable to return : OnCreateView Function  

     override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? {
            super.onCreateView(inflater, container, savedInstanceState)
    
            val view1 = inflater?.inflate(R.layout.fragment_home, container, false)
            val recyclerview = view1!!.findViewById<RecyclerView>(R.id.recycler_view)
    
            recyclerview.layoutManager = LinearLayoutManager(this.activity)
    
    
            //val name3: Array<Articles> =
    
    
            recyclerview.adapter = CustomAdaptor(fetchJson())
    
            return view1
    
        }



Fetchjson function



        fun fetchJson(): Array<Articles> {
        println("Attempting to fetch JSON")
        val url1 = "https://go-api-api.herokuapp.com/"

        //var a1 = Articles(1, "rsdfd", "fdsadfd", 2345, 3)

        lateinit var name2: Array<Articles>  //Initialized name2

        val request = Request.Builder().url(url1).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()

                try {
                    name2 = gson.fromJson(body, Array<Articles>::class.java)  //Updating value of name2
                }
                catch (e: Exception){
                    print("Error roroorirorr")
                    print(e)
                }
            }

            override fun onFailure(call: Call?, e: IOException?) {
                println("Faild to execute request")
            }
        })
        return name2   //returning name2
    }



The `CustomAdaptor` takes the input `Article` class. I have created a late initialized variable name2. In fetchjson, value of json does not get updated.

#error shown by Android Studio.

>kotlin.UninitializedPropertyAccessException: lateinit property name2 has not been initialized

How should I declare the variable, so as to get it updated ?