2015-05-31 60 views
6

我的應用程序出現問題,我想創建一個連接到我的服務器的簡單XMPP客戶端。 我在啓動應用程序時遇到了以下問題(編譯運行無問題),但我的應用程序立即關閉。Smack引發「NoClassDefFoundError:失敗的解決方案:Lorg/jxmpp/util/XmppStringUtils」

java.lang.NoClassDefFoundError: Failed resolution of: Lorg/jxmpp/util/XmppStringUtils; 
     at org.jivesoftware.smack.provider.ProviderManager.getKey(ProviderManager.java:314) 
     at org.jivesoftware.smack.provider.ProviderManager.addStreamFeatureProvider(ProviderManager.java:304) 
     at org.jivesoftware.smack.provider.ProviderManager.addLoader(ProviderManager.java:140) 
     at org.jivesoftware.smack.initializer.UrlInitializer.initialize(UrlInitializer.java:54) 
     at org.jivesoftware.smack.SmackInitialization.loadSmackClass(SmackInitialization.java:232) 
     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.ConnectionConfiguration.<clinit>(ConnectionConfiguration.java:38) 
     at org.reisacher.zapp.Main.login(Main.java:30) 
     at org.reisacher.zapp.Main.onCreate(Main.java:73) 
     at android.app.Activity.performCreate(Activity.java:5990) 
     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) 
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278) 
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390) 
     at android.app.ActivityThread.access$800(ActivityThread.java:151) 
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 
     at android.os.Handler.dispatchMessage(Handler.java:102) 
     at android.os.Looper.loop(Looper.java:135) 
     at android.app.ActivityThread.main(ActivityThread.java:5257) 
     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:903) 
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 
Caused by: java.lang.ClassNotFoundException: Didn't find class "org.jxmpp.util.XmppStringUtils" on path: DexPathList[[zip file "/data/app/org.reisacher.zapp-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.provider.ProviderManager.getKey(ProviderManager.java:314) 
at org.jivesoftware.smack.provider.ProviderManager.addStreamFeatureProvider(ProviderManager.java:304) 
            at org.jivesoftware.smack.provider.ProviderManager.addLoader(ProviderManager.java:140) 
            at org.jivesoftware.smack.initializer.UrlInitializer.initialize(UrlInitializer.java:54) 
            at org.jivesoftware.smack.SmackInitialization.loadSmackClass(SmackInitialization.java:232) 
            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.ConnectionConfiguration.<clinit>(ConnectionConfiguration.java:38) 
            at org.reisacher.zapp.Main.login(Main.java:30) 
            at org.reisacher.zapp.Main.onCreate(Main.java:73) 
            at android.app.Activity.performCreate(Activity.java:5990) 
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) 
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278) 
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390) 
            at android.app.ActivityThread.access$800(ActivityThread.java:151) 
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 
            at android.os.Handler.dispatchMessage(Handler.java:102) 
            at android.os.Looper.loop(Looper.java:135) 
            at android.app.ActivityThread.main(ActivityThread.java:5257) 
            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:903) 
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 
Suppressed: java.lang.ClassNotFoundException: org.jxmpp.util.XmppStringUtils 
     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) 
     ... 27 more 
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available 

但我有點找不到有關失蹤 「XmppStringUtils」

這東西是在第30行

public void login() throws XMPPException, IOException, SmackException { 
    XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder() 
      .setServiceName("reisacher.de") 
      .setHost("192.168.178.6") 
      .setPort(5222) 
      .build(); 

    AbstractXMPPConnection connection = new XMPPTCPConnection(config); 
    connection.connect(); 
    connection.login(username, password); 
} 

代碼,這是我進口

import org.jivesoftware.smack.AbstractXMPPConnection; 
import org.jivesoftware.smack.SmackException; 
import org.jivesoftware.smack.XMPPException; 
import org.jivesoftware.smack.tcp.XMPPTCPConnection; 
import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration; 

加上我的build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules. 
apply plugin: 'jetty' 
buildscript { 
    repositories { 
     maven { 
      url 'https://oss.sonatype.org/content/repositories/snapshots' 
     } 
     mavenCentral() 
    } 
    dependencies { 
     classpath 'com.android.tools.build:gradle:1.2.3' 
    } 
} 

dependencies { 
    compile "org.igniterealtime.smack:smack-android:4.1.1" 
    compile "org.igniterealtime.smack:smack-tcp:4.1.1" 
    // optional features 
    compile "org.igniterealtime.smack:smack-android-extensions:4.1.1" 
    compile "org.igniterealtime.smack:smack-core:4.1.1" 
} 

allprojects { 
    repositories { 
     jcenter() 
    } 
} 

謝謝

+0

你解決了這個錯誤? – CoronaPintu

+0

是的,我忘了在第二個build.gradle文件中添加依賴關係。 檢查您是否擁有$ root/build.gradle和$ root/app/build.gradle中的所有依賴項。這解決了我的錯誤 –

回答

2

NoClassDefFoundError's javadoc

Thrown if the Java Virtual Machine or a ClassLoader instance tries to load in the definition of a class (as part of a normal method call or as part of creating a new instance using the new expression) and no definition of the class could be found.

Java使用動態鏈接,這意味着符號(類名,...)第一次使用時有聯繫。正如Mohit已經指出的那樣,看起來你缺少JXMPP庫,這是Smack的(傳遞)依賴。我假設你只需將Smack添加到libs/文件夾中就可以將Smack添加到您的項目中。不建議使用這種方法,因爲您很容易錯過Smack的一種過度依賴,就像它發生在您身上一樣。而是使用一個能夠解決像Maven或Gradle這樣的依賴關係的構建系統。另請參見:

+0

謝謝,忘了在第二個.gradle文件中添加「編譯...」行。像現在一樣的魅力,沒有手動圖書館工作 –

8

您需要四個額外的jar文件。

1)jxmpp-core.jar添加

2)jxmpp-jid.jar

3)jxmpp-STRINGPREP-的libidn

4)jxmpp-util的緩存

你可以從下面的鏈接下載它們。

https://oss.sonatype.org/content/repositories/releases/org/jxmpp/

+2

感謝實際送我到庫而不是隻是說「使用maven」 –

+0

阿門到... –

3

問題來自於推了更新的錯誤一個依賴de.measite.minidns。所以我通過排除自動依賴和包括上一個穩定版本來解決這個問題。它解決了我的問題。

compile('org.igniterealtime.smack:smack-android-extensions:4.2.0') { 
    exclude group: 'de.measite.minidns' 
} 
compile('org.igniterealtime.smack:smack-tcp:4.2.0') { 
    exclude group: 'de.measite.minidns' 
} 
compile group: 'de.measite.minidns', name: 'minidns-hla', version: '0.2.2' 
+0

你節省了我的一天。非常感謝! –

相關問題