title: FatalException using HttpClient in AsyncTask with Android
body: <p>I'm at a loss here. I'm attempting to populate a List in my Activity using data pulled from a RESTful API. I've created the API layer that talks (successfully) with the API using the Apache HttpClient library (org.apache.http.client). However, when I attempted to connect the Activity with the API layer (through an AsyncTask) calamity ensued. I removed the API layer from the code in question and instead embedded the simplest example I could think of to try and isolate the problem (to no avail). Here's the code in question:</p>
  
  <pre><code>public class MyActivity extends Activity {
  
  @Override
  protected void onCreate( Bundle savedInstanceState ) {
  
      super.onCreate( savedInstanceState );
      setContentView( R.layout.main );
  }
  
  @Override
  protected void onResume() {
  
      super.onResume();
      new GetEventsTask().execute();
  }
  
  private class GetEventsTask extends AsyncTask&lt;Object, Integer, List&lt;IEvent&gt;&gt; {
  
      @Override
      protected List&lt;IEvent&gt; doInBackground( Object... params ) {
  
          fetch();
          return null;
      }
  
      @Override
      protected void onPostExecute( List&lt;IEvent&gt; events ) {
  
          Toast.makeText( getApplicationContext(), "Success", Toast.LENGTH_SHORT ).show();
      }
  
      private void fetch() {
          CloseableHttpClient client = HttpClients.createDefault();
          HttpPost httpPost = new HttpPost( "https://someurl.com/login" );
  
          List&lt;NameValuePair&gt; data = new ArrayList&lt;NameValuePair&gt;();
          data.add( new BasicNameValuePair( "username", "hai" ) );
          data.add( new BasicNameValuePair( "password", "kthxbye" ) );
  
          try {
              httpPost.setEntity( new UrlEncodedFormEntity( data ) );
              CloseableHttpResponse response = client.execute( httpPost );
          } catch( Exception e ) {
              Toast.makeText( getApplicationContext(), "Caught Exception", Toast.LENGTH_SHORT ).show();
          }
      }
  }
  </code></pre>
  
  <p>And here is the stack trace:</p>
  
  <pre><code>10-16 19:36:04.264: ERROR/AndroidRuntime(633): FATAL EXCEPTION: AsyncTask #1
      java.lang.RuntimeException: An error occured while executing doInBackground()
      at android.os.AsyncTask$3.done(AsyncTask.java:200)
      at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)
      at java.util.concurrent.FutureTask.setException(FutureTask.java:125)
      at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308)
      at java.util.concurrent.FutureTask.run(FutureTask.java:138)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
      at java.lang.Thread.run(Thread.java:1019)
      Caused by: java.lang.ExceptionInInitializerError
      at org.apache.http.impl.conn.PoolingHttpClientConnectionManager$InternalConnectionFactory.&lt;init&gt;(PoolingHttpClientConnectionManager.java:487)
      at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.&lt;init&gt;(PoolingHttpClientConnectionManager.java:147)
      at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.&lt;init&gt;(PoolingHttpClientConnectionManager.java:136)
      at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.&lt;init&gt;(PoolingHttpClientConnectionManager.java:112)
      at org.apache.http.impl.client.HttpClientBuilder.build(HttpClientBuilder.java:727)
      at org.apache.http.impl.client.HttpClients.createDefault(HttpClients.java:58)
      at ca.redacted.app.MyActivity$GetEventsTask.fetch(MyActivity.java:70)
      at ca.redacted.app.MyActivity$GetEventsTask.doInBackground(MyActivity.java:49)
      at ca.redacted.app.MyActivity$GetEventsTask.doInBackground(MyActivity.java:44)
      at android.os.AsyncTask$2.call(AsyncTask.java:185)
      at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
      ... 4 more
      Caused by: java.lang.ExceptionInInitializerError
      at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.&lt;init&gt;(ManagedHttpClientConnectionFactory.java:72)
      at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.&lt;init&gt;(ManagedHttpClientConnectionFactory.java:84)
      at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.&lt;clinit&gt;(ManagedHttpClientConnectionFactory.java:59)
      ... 15 more
      Caused by: java.lang.NoSuchFieldError: org.apache.http.message.BasicLineFormatter.INSTANCE
      at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.&lt;init&gt;(DefaultHttpRequestWriterFactory.java:52)
      at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.&lt;init&gt;(DefaultHttpRequestWriterFactory.java:56)
      at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.&lt;clinit&gt;(DefaultHttpRequestWriterFactory.java:46)
      ... 18 more
  </code></pre>
  
  <p>I'm relatively new to Android programming (and haven't touched Java in a while), so any help is greatly appreciated.</p>
  
  <p><strong>Updated</strong>
  Based on a debug run, this is the line that is throwing the FatalException</p>
  
  <p>CloseableHttpClient client = HttpClients.createDefault();</p>
  
  <p><strong>Updated Again</strong></p>
  
  <p>Switching to use the Android supplied DefaultHttpClient implementation solved the problem (in case anyone else runs into trouble using the Apache version). Still don't know what was causing me grief with the other library.</p>