title: android : cannot create connection to openfire
body: <p>I am trying to create connection to open fire in my <code>ConnectionAsyncTask</code> class.
  I am using Smack library <code>v4.13</code></p>
  
  <p>Following is the code:</p>
  
  <pre><code>public class ConnectionAsyncTask extends AsyncTask&lt;Void, Void, Void&gt; {
  
      public ConnectionAsyncTask() {
  
      }
  
      @Override
      protected Void doInBackground(Void... params) {
  
          XMPPTCPConnectionConfiguration.Builder config = XMPPTCPConnectionConfiguration.builder();
          config.setServiceName(HOST);
          config.setHost(HOST);
          config.setPort(PORT);
          config.setDebuggerEnabled(true);
  
          mConnection = new XMPPTCPConnection(config.build());
  
          try {
              mConnection.connect();
              Log.i("connect", "connected");
          } catch (SmackException e) {
              e.printStackTrace();
          } catch (IOException e) {
              e.printStackTrace();
          } catch (XMPPException e) {
              e.printStackTrace();
          }
  
          return null;
      }
  }
  </code></pre>
  
  <p>But the above code is throwing the following error:</p>
  
  <pre><code>08-20 13:03:29.573   3138-26629/com.example.hsoni.corpchat E/AndroidRuntime﹕ FATAL EXCEPTION: AsyncTask #4
      Process: com.example.hsoni.corpchat, PID: 3138
      java.lang.RuntimeException: An error occured while executing doInBackground()
              at android.os.AsyncTask$3.done(AsyncTask.java:304)
              at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
              at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
              at java.util.concurrent.FutureTask.run(FutureTask.java:242)
              at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
              at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
              at java.lang.Thread.run(Thread.java:818)
       Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Ljavax/naming/directory/InitialDirContext;
              at org.jivesoftware.smack.util.dns.javax.JavaxResolver.&lt;clinit&gt;(JavaxResolver.java:50)
              at java.lang.Class.classForName(Native Method)
              at java.lang.Class.forName(Class.java:309)
              at org.jivesoftware.smack.SmackInitialization.loadSmackClass(SmackInitialization.java:213)
              at org.jivesoftware.smack.SmackInitialization.parseClassesToLoad(SmackInitialization.java:193)
              at org.jivesoftware.smack.SmackInitialization.processConfigFile(SmackInitialization.java:163)
              at org.jivesoftware.smack.SmackInitialization.processConfigFile(SmackInitialization.java:148)
              at org.jivesoftware.smack.SmackInitialization.&lt;clinit&gt;(SmackInitialization.java:116)
              at org.jivesoftware.smack.SmackConfiguration.getVersion(SmackConfiguration.java:96)
              at org.jivesoftware.smack.ConnectionConfiguration.&lt;clinit&gt;(ConnectionConfiguration.java:38)
              at org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration.builder(XMPPTCPConnectionConfiguration.java:80)
              at com.example.hsoni.corpchat.SignUpActivity$ConnectionAsyncTask.doInBackground(SignUpActivity.java:73)
              at com.example.hsoni.corpchat.SignUpActivity$ConnectionAsyncTask.doInBackground(SignUpActivity.java:64)
              at android.os.AsyncTask$2.call(AsyncTask.java:292)
              at java.util.concurrent.FutureTask.run(FutureTask.java:237)
              at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
              at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
              at java.lang.Thread.run(Thread.java:818)
       Caused by: java.lang.ClassNotFoundException: Didn't find class "javax.naming.directory.InitialDirContext" on path: DexPathList[[zip file "/data/app/com.example.hsoni.corpchat-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
              at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
              at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
              at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
              at org.jivesoftware.smack.util.dns.javax.JavaxResolver.&lt;clinit&gt;(JavaxResolver.java:50)
              at java.lang.Class.classForName(Native Method)
              at java.lang.Class.forName(Class.java:309)
              at org.jivesoftware.smack.SmackInitialization.loadSmackClass(SmackInitialization.java:213)
              at org.jivesoftware.smack.SmackInitialization.parseClassesToLoad(SmackInitialization.java:193)
              at org.jivesoftware.smack.SmackInitialization.processConfigFile(SmackInitialization.java:163)
              at org.jivesoftware.smack.SmackInitialization.processConfigFile(SmackInitialization.java:148)
              at org.jivesoftware.smack.SmackInitialization.&lt;clinit&gt;(SmackInitialization.java:116)
              at org.jivesoftware.smack.SmackConfiguration.getVersion(SmackConfiguration.java:96)
              at org.jivesoftware.smack.ConnectionConfiguration.&lt;clinit&gt;(ConnectionConfiguration.java:38)
              at org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration.builder(XMPPTCPConnectionConfiguration.java:80)
              at com.example.hsoni.corpchat.SignUpActivity$ConnectionAsyncTask.doInBackground(SignUpActivity.java:73)
              at com.example.hsoni.corpchat.SignUpActivity$ConnectionAsyncTask.doInBackground(SignUpActivity.java:64)
              at android.os.AsyncTask$2.call(AsyncTask.java:292)
              at java.util.concurrent.FutureTask.run(FutureTask.java:237)
              at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
              at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
              at java.lang.Thread.run(Thread.java:818)
      Suppressed: java.lang.ClassNotFoundException: javax.naming.directory.InitialDirContext
              at java.lang.Class.classForName(Native Method)
              at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
              at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
              at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
              ... 20 more
       Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
  </code></pre>
  
  <p><strong>Note:</strong> I included all the libraries listed <a href="https://www.igniterealtime.org/builds/smack/docs/latest/documentation/gettingstarted.html" rel="nofollow">JAR Files and Requirements</a> in my project.</p>