title: when init Retrofit I get error: KotlinNullPointerException
body: <pre><code>class TransportService {
      companion object {
          private val waitressCallRestClient =  RestClientFactory.createRestClient(WaitressCallRestClient::class.java)
  
          private val TAG = TransportService::class.java.name
  
          init {
              Debug.d(TAG, "TransportService_initialize")
         }
      }
  }
  </code></pre>
  
  <p>here RestClientFactory.kt</p>
  
  <pre><code>object RestClientFactory {
      private val gsonBuilder = GsonUtil.gsonbuilder
      var gson: Gson? = null
          private set
      private val CONNECTION_TIME_OUT_SEC = 60
      private val READ_TIME_OUT_SEC = 60
      private val WRITE_TIME_OUT_SEC = 60
      private var httpClient: OkHttpClient.Builder? = null
      private val httpLoggingInterceptor = HttpLoggingInterceptor()
          .setLevel(HttpLoggingInterceptor.Level.BODY)
  
      private val TAG = RestClientFactory::class.java.name
  
      private val builder = Retrofit.Builder()
          .baseUrl(BuildConfig.API_BASE_URL)
          .addConverterFactory(GsonConverterFactory.create(gson!!))
          .addConverterFactory(QueryConverterFactory.create())
          .client(httpClient!!.build())
  
      var retrofit = builder.build()
          private set
  
  
  
      fun &lt;T&gt; createRestClient(restClientClass: Class&lt;T&gt;): T {
          retrofit = builder.build()
          return retrofit.create(restClientClass)
      }
  }
  </code></pre>
  
  <p>But I get runtime error in this line:</p>
  
  <pre><code>.addConverterFactory(GsonConverterFactory.create(gson!!))
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>11-08 13:26:58.104 E/AndroidRuntime(13653): FATAL EXCEPTION: main
  11-08 13:26:58.104 E/AndroidRuntime(13653): Process: com.myproject.android.debug, PID: 13653
  11-08 13:26:58.104 E/AndroidRuntime(13653): java.lang.ExceptionInInitializerError
  11-08 13:26:58.104 E/AndroidRuntime(13653):     at com.myproject.android.service.TransportService.&lt;clinit&gt;(TransportService.kt:25)
  11-08 13:26:58.104 E/AndroidRuntime(13653):     at com.myproject.android.viewmodel.FeedbackViewModel$doClickSend$1.invokeSuspend(FeedbackViewModel.kt:39)
  11-08 13:26:58.104 E/AndroidRuntime(13653):     at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
  11-08 13:26:58.104 E/AndroidRuntime(13653):     at kotlinx.coroutines.DispatchedTask.run(Dispatched.kt:241)
  11-08 13:26:58.104 E/AndroidRuntime(13653):     at android.os.Handler.handleCallback(Handler.java:739)
  11-08 13:26:58.104 E/AndroidRuntime(13653):     at android.os.Handler.dispatchMessage(Handler.java:95)
  11-08 13:26:58.104 E/AndroidRuntime(13653):     at android.os.Looper.loop(Looper.java:148)
  11-08 13:26:58.104 E/AndroidRuntime(13653):     at android.app.ActivityThread.main(ActivityThread.java:5417)
  11-08 13:26:58.104 E/AndroidRuntime(13653):     at java.lang.reflect.Method.invoke(Native Method)
  11-08 13:26:58.104 E/AndroidRuntime(13653):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
  11-08 13:26:58.104 E/AndroidRuntime(13653):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
  11-08 13:26:58.104 E/AndroidRuntime(13653): Caused by: kotlin.KotlinNullPointerException
  11-08 13:26:58.104 E/AndroidRuntime(13653):     at com.myproject.android.api.RestClientFactory.&lt;clinit&gt;(RestClientFactory.kt:40)
  11-08 13:26:58.104 E/AndroidRuntime(13653):     ... 11 more
  </code></pre>