本文介绍了初始化例外" NoClassDefFoundError的:javax.naming.directory.InitialDirContext"啪4.1在Android上使用时,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用拍击我的项目。我有我的一些其中的工作非常出色早期项目的pviously使用aSmack $ P $。然而啪是给我奇怪的例外。

下面是我的初始code样子 -

 公共无效的init(字符串用户名,字符串密码)抛出IOException异常,XMPPException,SmackException {
        mConnection =新XMPPTCPConnection(用户名,密码,HOST_NAME); //这是产生异常的行        mConnection.connect();
        mConnection.login();        mChatManager = ChatManager.getInstanceFor(mConnection);
        mChatManager.addChatListener(本);
    }

下面是logcat的输出 -

  java.lang.IllegalStateException:无法执行活动的方法
            在android.view.View $ 1.onClick(View.java:3690)
            在android.view.View.performClick(View.java:4192)
            在android.view.View $ PerformClick.run(View.java:17248)
            在android.os.Handler.handleCallback(Handler.java:615)
            在android.os.Handler.dispatchMessage(Handler.java:92)
            在android.os.Looper.loop(Looper.java:137)
            在android.app.ActivityThread.main(ActivityThread.java:4950)
            在java.lang.reflect.Method.invokeNative(本机方法)
            在java.lang.reflect.Method.invoke(Method.java:511)
            在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:997)
            在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:764)
            在dalvik.system.NativeStart.main(本机方法)
     java.lang.reflect.InvocationTargetException:产生的原因
            在java.lang.reflect.Method.invokeNative(本机方法)
            在java.lang.reflect.Method.invoke(Method.java:511)
            在android.view.View $ 1.onClick(View.java:3685)
在android.view.View.performClick(View.java:4192)
在android.view.View $ PerformClick.run(View.java:17248)
在android.os.Handler.handleCallback(Handler.java:615)
在android.os.Handler.dispatchMessage(Handler.java:92)
在android.os.Looper.loop(Looper.java:137)
在android.app.ActivityThread.main(ActivityThread.java:4950)
在java.lang.reflect.Method.invokeNative(本机方法)
在java.lang.reflect.Method.invoke(Method.java:511)
在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:997)
在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:764)
在dalvik.system.NativeStart.main(本机方法)
     java.lang.ExceptionInInitializerError:产生的原因
            在test.Managers.XMPPManager.init(XMPPManager.java:42)
            在test.LoginActivity.onLoginClick(LoginActivity.java:46)
在java.lang.reflect.Method.invokeNative(本机方法)
在java.lang.reflect.Method.invoke(Method.java:511)
在android.view.View $ 1.onClick(View.java:3685)
在android.view.View.performClick(View.java:4192)
在android.view.View $ PerformClick.run(View.java:17248)
在android.os.Handler.handleCallback(Handler.java:615)
在android.os.Handler.dispatchMessage(Handler.java:92)
在android.os.Looper.loop(Looper.java:137)
在android.app.ActivityThread.main(ActivityThread.java:4950)
在java.lang.reflect.Method.invokeNative(本机方法)
在java.lang.reflect.Method.invoke(Method.java:511)
在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:997)
在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:764)
在dalvik.system.NativeStart.main(本机方法)
     java.lang.ExceptionInInitializerError:产生的原因
            在org.jivesoftware.smack.SmackConfiguration.getVersion(SmackConfiguration.java:96)
            在org.jivesoftware.smack.AbstractXMPPConnection< clinit>(AbstractXMPPConnection.java:98)
在test.Managers.XMPPManager.init(XMPPManager.java:42)
在test.LoginActivity.onLoginClick(LoginActivity.java:46)
在java.lang.reflect.Method.invokeNative(本机方法)
在java.lang.reflect.Method.invoke(Method.java:511)
在android.view.View $ 1.onClick(View.java:3685)
在android.view.View.performClick(View.java:4192)
在android.view.View $ PerformClick.run(View.java:17248)
在android.os.Handler.handleCallback(Handler.java:615)
在android.os.Handler.dispatchMessage(Handler.java:92)
在android.os.Looper.loop(Looper.java:137)
在android.app.ActivityThread.main(ActivityThread.java:4950)
在java.lang.reflect.Method.invokeNative(本机方法)
在java.lang.reflect.Method.invoke(Method.java:511)
在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:997)
在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:764)
在dalvik.system.NativeStart.main(本机方法)
     java.lang.ExceptionInInitializerError:产生的原因
            在java.lang.Class.classForName(本机方法)
            在java.lang.Class.forName(Class.java:217)
            在org.jivesoftware.smack.SmackInitialization.loadSmackClass(SmackInitialization.java:213)
            在org.jivesoftware.smack.SmackInitialization.parseClassesToLoad(SmackInitialization.java:193)
            在org.jivesoftware.smack.SmackInitialization.processConfigFile(SmackInitialization.java:163)
            在org.jivesoftware.smack.SmackInitialization.processConfigFile(SmackInitialization.java:148)
            在org.jivesoftware.smack.SmackInitialization< clinit>(SmackInitialization.java:116)
在org.jivesoftware.smack.SmackConfiguration.getVersion(SmackConfiguration.java:96)
在org.jivesoftware.smack.AbstractXMPPConnection< clinit>(AbstractXMPPConnection.java:98)
在test.Managers.XMPPManager.init(XMPPManager.java:42)
在test.LoginActivity.onLoginClick(LoginActivity.java:46)
在java.lang.reflect.Method.invokeNative(本机方法)
在java.lang.reflect.Method.invoke(Method.java:511)
在android.view.View $ 1.onClick(View.java:3685)
在android.view.View.performClick(View.java:4192)
在android.view.View $ PerformClick.run(View.java:17248)
在android.os.Handler.handleCallback(Handler.java:615)
在android.os.Handler.dispatchMessage(Handler.java:92)
在android.os.Looper.loop(Looper.java:137)
在android.app.ActivityThread.main(ActivityThread.java:4950)
在java.lang.reflect.Method.invokeNative(本机方法)
在java.lang.reflect.Method.invoke(Method.java:511)
在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:997)
在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:764)
在dalvik.system.NativeStart.main(本机方法)
     java.lang.NoClassDefFoundError的:引起javax.naming.directory.InitialDirContext
            在org.jivesoftware.smack.util.dns.javax.JavaxResolver< clinit>(JavaxResolver.java:50)
在java.lang.Class.classForName(本机方法)
在java.lang.Class.forName(Class.java:217)
在org.jivesoftware.smack.SmackInitialization.loadSmackClass(SmackInitialization.java:213)
在org.jivesoftware.smack.SmackInitialization.parseClassesToLoad(SmackInitialization.java:193)
在org.jivesoftware.smack.SmackInitialization.processConfigFile(SmackInitialization.java:163)
在org.jivesoftware.smack.SmackInitialization.processConfigFile(SmackInitialization.java:148)
在org.jivesoftware.smack.SmackInitialization< clinit>(SmackInitialization.java:116)
在org.jivesoftware.smack.SmackConfiguration.getVersion(SmackConfiguration.java:96)
在org.jivesoftware.smack.AbstractXMPPConnection< clinit>(AbstractXMPPConnection.java:98)
在test.Managers.XMPPManager.init(XMPPManager.java:42)
在test.LoginActivity.onLoginClick(LoginActivity.java:46)
在java.lang.reflect.Method.invokeNative(本机方法)
在java.lang.reflect.Method.invoke(Method.java:511)
在android.view.View $ 1.onClick(View.java:3685)
在android.view.View.performClick(View.java:4192)
在android.view.View $ PerformClick.run(View.java:17248)
在android.os.Handler.handleCallback(Handler.java:615)
在android.os.Handler.dispatchMessage(Handler.java:92)
在android.os.Looper.loop(Looper.java:137)
在android.app.ActivityThread.main(ActivityThread.java:4950)
在java.lang.reflect.Method.invokeNative(本机方法)
在java.lang.reflect.Method.invoke(Method.java:511)
在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:997)
在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:764)
在dalvik.system.NativeStart.main(本机方法)

我已经检查了一些论坛帖子它说,启用ProGuard的,当这个问题出现。然而,在我的项目Progaurd被禁用。

任何想法可能导致此异常?

更新: - 结果
这是我app.gradle文件的样子 -

  {相关性
    编译文件树(导演:'库',包括:['的* .jar'])
    编译org.igniterealtime.smack:咂嘴-java7目录:4.1.0
    //以XMPPTCPConnection
    编译org.igniterealtime.smack:咂嘴-TCP:4.1.0
    //以XMPP-IM(RFC 6121)的支持(名册,螺纹聊天,...)
    编译org.igniterealtime.smack:咂嘴-IM:4.1.0
    //可选的XMPP扩展的支持
    编译org.igniterealtime.smack:咂嘴的扩展:4.1.0
    编译com.android.support:appcompat-v7:21.0.3
    编制项目(:XXX)
    编制项目(:XXX)
    编制项目(:XXX)
    编译('com.crashlytics.sdk.android:crashlytics:2.2.4@aar'){
        传递= TRUE;
    }
}


解决方案

不要在Android项目添加咂嘴,java7目录,使用咂嘴,而不是机器人。

另外拍击4.1.1的最新版本啪

I am trying to use Smack for my project. I have previously used aSmack in some of my earlier projects which worked really well. However Smack is giving me weird exceptions.

Here's my initialization code looks like -

public void init(String username, String password) throws IOException, XMPPException, SmackException {
        mConnection = new XMPPTCPConnection(username, password, HOST_NAME); //This is the line which generates the exception

        mConnection.connect();
        mConnection.login();

        mChatManager = ChatManager.getInstanceFor(mConnection);
        mChatManager.addChatListener(this);
    }

Here's the Logcat output -

java.lang.IllegalStateException: Could not execute method of the activity
            at android.view.View$1.onClick(View.java:3690)
            at android.view.View.performClick(View.java:4192)
            at android.view.View$PerformClick.run(View.java:17248)
            at android.os.Handler.handleCallback(Handler.java:615)
            at android.os.Handler.dispatchMessage(Handler.java:92)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4950)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:997)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:764)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.reflect.InvocationTargetException
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at android.view.View$1.onClick(View.java:3685)
            at android.view.View.performClick(View.java:4192)
            at android.view.View$PerformClick.run(View.java:17248)
            at android.os.Handler.handleCallback(Handler.java:615)
            at android.os.Handler.dispatchMessage(Handler.java:92)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4950)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:997)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:764)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.ExceptionInInitializerError
            at test.Managers.XMPPManager.init(XMPPManager.java:42)
            at test.LoginActivity.onLoginClick(LoginActivity.java:46)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at android.view.View$1.onClick(View.java:3685)
            at android.view.View.performClick(View.java:4192)
            at android.view.View$PerformClick.run(View.java:17248)
            at android.os.Handler.handleCallback(Handler.java:615)
            at android.os.Handler.dispatchMessage(Handler.java:92)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4950)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:997)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:764)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.ExceptionInInitializerError
            at org.jivesoftware.smack.SmackConfiguration.getVersion(SmackConfiguration.java:96)
            at org.jivesoftware.smack.AbstractXMPPConnection.<clinit>(AbstractXMPPConnection.java:98)
            at test.Managers.XMPPManager.init(XMPPManager.java:42)
            at test.LoginActivity.onLoginClick(LoginActivity.java:46)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at android.view.View$1.onClick(View.java:3685)
            at android.view.View.performClick(View.java:4192)
            at android.view.View$PerformClick.run(View.java:17248)
            at android.os.Handler.handleCallback(Handler.java:615)
            at android.os.Handler.dispatchMessage(Handler.java:92)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4950)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:997)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:764)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.ExceptionInInitializerError
            at java.lang.Class.classForName(Native Method)
            at java.lang.Class.forName(Class.java:217)
            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.<clinit>(SmackInitialization.java:116)
            at org.jivesoftware.smack.SmackConfiguration.getVersion(SmackConfiguration.java:96)
            at org.jivesoftware.smack.AbstractXMPPConnection.<clinit>(AbstractXMPPConnection.java:98)
            at test.Managers.XMPPManager.init(XMPPManager.java:42)
            at test.LoginActivity.onLoginClick(LoginActivity.java:46)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at android.view.View$1.onClick(View.java:3685)
            at android.view.View.performClick(View.java:4192)
            at android.view.View$PerformClick.run(View.java:17248)
            at android.os.Handler.handleCallback(Handler.java:615)
            at android.os.Handler.dispatchMessage(Handler.java:92)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4950)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:997)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:764)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.NoClassDefFoundError: javax.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:217)
            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.<clinit>(SmackInitialization.java:116)
            at org.jivesoftware.smack.SmackConfiguration.getVersion(SmackConfiguration.java:96)
            at org.jivesoftware.smack.AbstractXMPPConnection.<clinit>(AbstractXMPPConnection.java:98)
            at test.Managers.XMPPManager.init(XMPPManager.java:42)
            at test.LoginActivity.onLoginClick(LoginActivity.java:46)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at android.view.View$1.onClick(View.java:3685)
            at android.view.View.performClick(View.java:4192)
            at android.view.View$PerformClick.run(View.java:17248)
            at android.os.Handler.handleCallback(Handler.java:615)
            at android.os.Handler.dispatchMessage(Handler.java:92)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4950)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:997)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:764)
            at dalvik.system.NativeStart.main(Native Method)

I have checked some forum posts which says that this problem comes when proguard is enabled. However in my project Progaurd is disabled.

Any idea what could cause this exception?

Update:-
This is how my app.gradle file looks like -

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'org.igniterealtime.smack:smack-java7:4.1.0'
    // Optional for XMPPTCPConnection
    compile 'org.igniterealtime.smack:smack-tcp:4.1.0'
    // Optional for XMPP-IM (RFC 6121) support (Roster, Threaded Chats, …)
    compile 'org.igniterealtime.smack:smack-im:4.1.0'
    // Optional for XMPP extensions support
    compile 'org.igniterealtime.smack:smack-extensions:4.1.0'
    compile 'com.android.support:appcompat-v7:21.0.3'
    compile project(':xxx')
    compile project(':xxx')
    compile project(':xxx')
    compile('com.crashlytics.sdk.android:crashlytics:2.2.4@aar') {
        transitive = true;
    }
}
解决方案

Don't add smack-java7 on Android projects, use smack-android instead.

Also Smack 4.1.1 is the latest Smack version.

这篇关于初始化例外&QUOT; NoClassDefFoundError的:javax.naming.directory.InitialDirContext&QUOT;啪4.1在Android上使用时,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 23:22