title: Kotlin, Api Get request sometimes ends before returning anything
body: <p>I created an API request from a kotlin app to a server with Retrofit.
  Sometimes the request return nothing, but it always return the data inside web URL.</p>
  <p>My code</p>
  <pre><code>interface ApiService {
  
      @get:GET(&quot;main&quot;)
      val posts : Call&lt;List&lt;Products?&gt;?&gt;
  
  </code></pre>
  <pre><code>class mainConnector {
  
      fun MainConnector(): Call&lt;List&lt;Products?&gt;?&gt; {
  
          val logging = HttpLoggingInterceptor()
  
          logging.setLevel(HttpLoggingInterceptor.Level.BODY)
          val httpClient = OkHttpClient.Builder().addInterceptor(logging).build()
  
          val builder = Retrofit.Builder().baseUrl(ApiService.URL)
              .addConverterFactory(GsonConverterFactory.create())
              .client(httpClient)
              .build()
  
          val API = builder.create(ApiService::class.java)
          val call = API.posts
  
          return call
      }
  </code></pre>
  <p>This a part of activity that call the connector</p>
  <pre><code>        val obj = mainConnector()
          val call = obj.MainConnector()
  
          call.enqueue(object:Callback&lt;List&lt;Products?&gt;?&gt;{
              override fun onResponse(
                  call: Call&lt;List&lt;Products?&gt;?&gt;,
                  response: Response&lt;List&lt;Products?&gt;?&gt;
              ) {
  
                  var postlist : List&lt;Products?&gt;? = response.body() as List&lt;Products?&gt;
                  var list = mutableListOf&lt;Products?&gt;()
                  val listView: ListView = findViewById(R.id.listview)
                  listView.isClickable = true
  
                  for(i in postlist!!.indices) {
                      list.add(
                          Products(postlist!![i]!!.admindescription,
                          postlist!![i]!!.created_at,
                          postlist!![i]!!.description,
                          postlist!![i]!!.id,
                          postlist!![i]!!.link,
                          postlist!![i]!!.pname,
                          postlist!![i]!!.price,
                          postlist!![i]!!.smalldescription,
                          postlist!![i]!!.updated_at,
                          postlist!![i]!!.user_id,
                          postlist!![i]!!.image,
                          postlist!![i]!!.category,
                          postlist!![i]!!.phone,
                          postlist!![i]!!.telegram,
                          postlist!![i]!!.name)
                      )
                  }
  
                  var adapter = MyMainListAdapter(this@MainActivity,R.layout.custom_main_list, list)
                  listView.setOnItemClickListener{ parent, view, position, id -&gt;
                      val name = postlist!![position]!!.pname
                      val createdAt = postlist!![position]!!.created_at
                      val description = postlist!![position]!!.description
                      val id = postlist!![position]!!.id
                      val link = postlist!![position]!!.link
                      val price = postlist!![position]!!.price
                      val smalldescription = postlist!![position]!!.smalldescription
                      val updatedAt = postlist!![position]!!.updated_at
                      val userId = postlist!![position]!!.user_id
                      val category = postlist!![position]!!.category
                      val phone = postlist!![position]!!.phone
                      val telegram = postlist!![position]!!.telegram
                      val userName = postlist!![position]!!.name
  
                      val i = Intent(this@MainActivity, ProductActivity::class.java)
  
                      val image = ArrayList&lt;String?&gt;()
  
                      for(i in postlist!![position]!!.image!!) {
                          image.add(i)
                      }
  
                      i.putStringArrayListExtra(&quot;image&quot;, image)
                      i.putExtra(&quot;name&quot;, name)
                      i.putExtra(&quot;createdAt&quot;, createdAt)
                      i.putExtra(&quot;description&quot;, description)
                      i.putExtra(&quot;id&quot;, id)
                      i.putExtra(&quot;link&quot;, link)
                      i.putExtra(&quot;price&quot;, price)
                      i.putExtra(&quot;smalldescription&quot;, smalldescription)
                      i.putExtra(&quot;updatedAt&quot;, updatedAt)
                      i.putExtra(&quot;userId&quot;, userId)
                      i.putExtra(&quot;category&quot;, category)
                      i.putExtra(&quot;phone&quot;, phone)
                      i.putExtra(&quot;telegram&quot;, telegram)
                      i.putExtra(&quot;userName&quot;, userName)
  
                      startActivity(i)
                  }
                  listView.setAdapter(adapter)
              }
  
              override fun onFailure(call: Call&lt;List&lt;Products?&gt;?&gt;, t: Throwable) {
  
              }
  
          })
  </code></pre>
  <p>As I said it sometimes works, and sometimes doesn't. So what's the problem here? (I'm mainly a php, js programmer and I am new in android and kotlin)</p>