当前位置: 首页 > 面试题库 >

Smack引发“ NoClassDefFoundError:无法解析以下文件:Lorg / jxmpp / util / XmppStringUtils”

单昊穹
2023-03-14
问题内容

我的应用程序出现问题,我想创建一个连接到服务器的简单XMPP客户端。启动应用程序时遇到以下问题(编译过程没有问题),但是我的应用程序立即关闭。

   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()
    }
}

谢谢


问题答案:

从NoClassDefFoundError的javadoc:

如果Java虚拟机或ClassLoader实例尝试加载类的定义(作为常规方法调用的一部分或使用新表达式创建新实例的一部分)而抛出,则找不到该类的定义。

Java使用动态链接,这意味着在首次使用符号(类名,…)时就进行了链接。正如Mohit已经指出的那样,您似乎缺少了JXMPP库,它是Smack的(传递)依赖项。我假设您确实只是通过将Smack放入libs/文件夹中而将其添加到项目中。不建议使用这种方法,因为您很容易错过Smack的传统依赖,就像您遇到的那样。而是使用能够解决诸如Maven或Gradle之类的依赖关系的构建系统。也可以看看:

  • Smack 4.1自述文件和升级指南


 类似资料:
  • 这段代码在leapdroid中工作得很好,但我得到了错误模拟器: 我的代码是:

  • 我正在使用库。 我已经尝试更新最新版本:Retrofit2,Gson,Rxjava,OKHttp,HttpLoggingInterceptor...在文件 应用程序中的build.grade 但我出错了 在下面的代码中 <代码>构建。项目中的渐变: 谁知道我为什么会犯这个错误? 请告诉我如何修复它, 非常感谢。

  • 我正在使用方法向服务器发送录制的音频文件,但收到以下错误: 致命异常java.lang.noClassDefFoundError:解析失败:lorg/apache/http/util/args 下面是我的代码:

  • 我在tomcat 7本地应用程序服务器上使用JSP 1.2和JSTL或Spring的taglib声明。但是,无论文件是在WEB-INF/lib下还是在类路径的其他位置,我总是会收到这样的错误:绝对uri:http://java.sun.com/jsp/jstl/core无法在web.xml或与此应用程序一起部署的jar文件中解析绝对uri:http://www.springframework.or

  • 两天前,我犯了以下错误: 执行任务:[: app: assembleDebug] 配置项目:app registerResGeneratingTask已弃用,请使用registerGeneratedResFolders(FileCollection) 任务:app:buildInfoDebugLoader任务:app:preBuild-UP-DATE任务:core:preDebugBuild-up

  • 我正在学习OpenApi。我从Swagger那里得到了这个错误: TypeError: O是未定义的值parameter-row.jsx:149渲染root-injects.jsx:93React 8_renderValidatedComponentWithoutOwnerOrContext_renderValidatedComponent性能初始安装安装组件安装组件安装儿童_createInit