AnsweredAssumed Answered

java.lang.ClassNotFoundException: javax.naming.directory.InitialDirContext in Android

Question asked by Chaitanya Bhagvan on Jan 16, 2015
Latest reply on Jan 16, 2015 by Chaitanya Bhagvan

I am getting a ClassNotFoundException in an android app.

 

The entire stack trace is as follows

 

java.lang.NoClassDefFoundError: Failed resolution of: Ljavax/naming/directory/InitialDirContext;

            at org.jivesoftware.smack.util.dns.javax.JavaxResolver.<clinit>(JavaxResolver.java :50)

            at java.lang.Class.classForName(Native Method)

            at java.lang.Class.forName(Class.java:308)

            at org.jivesoftware.smack.SmackInitialization.loadSmackClass(SmackInitialization.j ava:216)

            at org.jivesoftware.smack.SmackInitialization.parseClassesToLoad(SmackInitializati on.java:196)

            at org.jivesoftware.smack.SmackInitialization.processConfigFile(SmackInitializatio n.java:166)

            at org.jivesoftware.smack.SmackInitialization.processConfigFile(SmackInitializatio n.java:151)

            at org.jivesoftware.smack.SmackInitialization.<clinit>(SmackInitialization.java:11 8)

            at org.jivesoftware.smack.SmackConfiguration.getVersion(SmackConfiguration.java:96 )

            at org.jivesoftware.smack.ConnectionConfiguration.<clinit>(ConnectionConfiguration .java:41)

            at sample.app.service.MessageService.onCreate(MessageService.java:60)

            at android.app.ActivityThread.handleCreateService(ActivityThread.java:2731)

            at android.app.ActivityThread.access$1800(ActivityThread.java:144)

            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1361)

            at android.os.Handler.dispatchMessage(Handler.java:102)

            at android.os.Looper.loop(Looper.java:135)

            at android.app.ActivityThread.main(ActivityThread.java:5221)

            at java.lang.reflect.Method.invoke(Native Method)

            at java.lang.reflect.Method.invoke(Method.java:372)

            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)

            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

     Caused by: java.lang.ClassNotFoundException: Didn't find class "javax.naming.directory.InitialDirContext" on path: DexPathList[[zip file "/data/app/sample.app-1/base.apk"],nativeLibraryDirectories=[/vendor/lib64, /system/lib64]]

            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.<clinit>(JavaxResolver.java :50)

            at java.lang.Class.classForName(Native Method)

            at java.lang.Class.forName(Class.java:308)

            at org.jivesoftware.smack.SmackInitialization.loadSmackClass(SmackInitialization.j ava:216)

            at org.jivesoftware.smack.SmackInitialization.parseClassesToLoad(SmackInitializati on.java:196)

            at org.jivesoftware.smack.SmackInitialization.processConfigFile(SmackInitializatio n.java:166)

            at org.jivesoftware.smack.SmackInitialization.processConfigFile(SmackInitializatio n.java:151)

            at org.jivesoftware.smack.SmackInitialization.<clinit>(SmackInitialization.java:11 8)

            at org.jivesoftware.smack.SmackConfiguration.getVersion(SmackConfiguration.java:96 )

            at org.jivesoftware.smack.ConnectionConfiguration.<clinit>(ConnectionConfiguration .java:41)

            at sample.app.service.MessageService.onCreate(MessageService.java:60)

            at android.app.ActivityThread.handleCreateService(ActivityThread.java:2731)

            at android.app.ActivityThread.access$1800(ActivityThread.java:144)

            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1361)

            at android.os.Handler.dispatchMessage(Handler.java:102)

            at android.os.Looper.loop(Looper.java:135)

            at android.app.ActivityThread.main(ActivityThread.java:5221)

            at java.lang.reflect.Method.invoke(Native Method)

            at java.lang.reflect.Method.invoke(Method.java:372)

            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)

            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

    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)

            ... 22 more

     Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available

 

 

My gradle file has the following dependencies

 

dependencies {

    compile "org.igniterealtime.smack:smack-android:4.1.0-beta1"

    compile "org.igniterealtime.smack:smack-tcp:4.1.0-beta1"

}

 

Could someone help me with this?

Outcomes