title: Exception when creating new instance of OkHttp3.OkHttpClient
body: <p>I'm trying to use <a href="https://github.com/square/okhttp" rel="nofollow noreferrer">OkHttp</a> to download a file from a webserver in an Android app. After creating a new Project with Android Studio (API level 28) I added a button and am ImageView to my Activity. The idea is to download the an image when I press the button and show it on the screen.</p>
  
  <p>I'm using the latest version of OkHttp, 3.14.0.</p>
  
  <p>I added <code>&lt;uses-permission android:name="android.permission.INTERNET"/&gt;</code> to the AndroidManifest.xml file.</p>
  
  <p>I tried to use the OkHttpClient exactly as described in the <a href="http://square.github.io/okhttp/#examples" rel="nofollow noreferrer">examples</a>. This is what my code looks like:</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
      ... // onCreate method
  
      public void btnClicked(View view) {
          new DownloadImageAsyncTask().execute("https://link.to/image.jpg");
      }
  
      public class DownloadImageAsyncTask extends AsyncTask&lt;String, Void, Bitmap&gt; {
  
          OkHttpClient client = new OkHttpClient();
  
          ... // override doInBackground()
      }
  }
  </code></pre>
  
  <p>When l run the app and press the button, the <code>btnClicked()</code> method is executed and the app crashes. The error occurs when calling <code>OkHttpClient()</code> no matter if I place it as a field in the <code>DownloadImageAsyncTask</code> class, as a local variable of the <code>doInBackground()</code> method or as a field in the <code>ManActivity</code> class.</p>
  
  <p>I've also ried to use the Builder (<code>new OkHttpClient.Builder().build()</code>) to initialize the object but with the same outcome.</p>
  
  <p>Here's the stack trace:</p>
  
  <pre><code>E/AndroidRuntime: FATAL EXCEPTION: main
      Process: com.myapp.httpstuff, PID: 17796
      java.lang.IllegalStateException: Could not execute method for android:onClick
          at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:390)
          at android.view.View.performClick(View.java:6597)
          at android.view.View.performClickInternal(View.java:6574)
          at android.view.View.access$3100(View.java:778)
          at android.view.View$PerformClick.run(View.java:25885)
          at android.os.Handler.handleCallback(Handler.java:873)
          at android.os.Handler.dispatchMessage(Handler.java:99)
          at android.os.Looper.loop(Looper.java:193)
          at android.app.ActivityThread.main(ActivityThread.java:6669)
          at java.lang.reflect.Method.invoke(Native Method)
          at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
       Caused by: java.lang.reflect.InvocationTargetException
          at java.lang.reflect.Method.invoke(Native Method)
          at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:385)
          at android.view.View.performClick(View.java:6597) 
          at android.view.View.performClickInternal(View.java:6574) 
          at android.view.View.access$3100(View.java:778) 
          at android.view.View$PerformClick.run(View.java:25885) 
          at android.os.Handler.handleCallback(Handler.java:873) 
          at android.os.Handler.dispatchMessage(Handler.java:99) 
          at android.os.Looper.loop(Looper.java:193) 
          at android.app.ActivityThread.main(ActivityThread.java:6669) 
          at java.lang.reflect.Method.invoke(Native Method) 
          at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) 
       Caused by: java.lang.BootstrapMethodError: Exception from call site #4 bootstrap method
          at okhttp3.internal.Util.&lt;clinit&gt;(Util.java:87)
          at okhttp3.internal.Util.immutableList(Util.java:234)
          at okhttp3.OkHttpClient.&lt;clinit&gt;(OkHttpClient.java:124)
          at com.myapp.httpstuff.MainActivity$DownloadImageAsyncTask.&lt;init&gt;(MainActivity.java:31)
          at com.myapp.httpstuff.MainActivity.btnClicked(MainActivity.java:26)
          at java.lang.reflect.Method.invoke(Native Method) 
          at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:385) 
          at android.view.View.performClick(View.java:6597) 
          at android.view.View.performClickInternal(View.java:6574) 
          at android.view.View.access$3100(View.java:778) 
          at android.view.View$PerformClick.run(View.java:25885) 
          at android.os.Handler.handleCallback(Handler.java:873) 
          at android.os.Handler.dispatchMessage(Handler.java:99) 
          at android.os.Looper.loop(Looper.java:193) 
          at android.app.ActivityThread.main(ActivityThread.java:6669) 
          at java.lang.reflect.Method.invoke(Native Method) 
          at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) 
       Caused by: java.lang.ClassCastException: Bootstrap method returned null
          at okhttp3.internal.Util.&lt;clinit&gt;(Util.java:87) 
          at okhttp3.internal.Util.immutableList(Util.java:234) 
          at okhttp3.OkHttpClient.&lt;clinit&gt;(OkHttpClient.java:124) 
          at com.myapp.httpstuff.MainActivity$DownloadImageAsyncTask.&lt;init&gt;(MainActivity.java:31) 
          at com.myapp.httpstuff.MainActivity.btnClicked(MainActivity.java:26) 
          at java.lang.reflect.Method.invoke(Native Method) 
          at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:385) 
          at android.view.View.performClick(View.java:6597) 
          at android.view.View.performClickInternal(View.java:6574) 
          at android.view.View.access$3100(View.java:778) 
          at android.view.View$PerformClick.run(View.java:25885) 
          at android.os.Handler.handleCallback(Handler.java:873) 
          at android.os.Handler.dispatchMessage(Handler.java:99) 
          at android.os.Looper.loop(Looper.java:193) 
          at android.app.ActivityThread.main(ActivityThread.java:6669) 
          at java.lang.reflect.Method.invoke(Native Method) 
          at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) 
  </code></pre>