Android 异常:'java.lang.NoClassDefFoundError: javax.jmdns.JmDNS'

发布于 2024-12-15 16:08:00 字数 3470 浏览 2 评论 0 原文

希望我的问题不太愚蠢,但我遇到了以下问题...

我正在将一个包含库 JmDNS 的 jar 导入到我的项目中。我的项目设置为像这样处理 JmDNS...

      setUp();
        try {
            peer = new PublicPeer("Aidan",6666,6667,this);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

     private void setUp(){
        android.net.wifi.WifiManager wifi =
               (android.net.wifi.WifiManager)
                  getSystemService(android.content.Context.WIFI_SERVICE);
        lock = wifi.createMulticastLock("Lock");
            lock.setReferenceCounted(true);
            lock.acquire();
       }

其中 lock = android.net.wifi.WifiManager.MulticastLock lock;PublicPeer peer;

当执行达到 时peer = new PublicPeer("Aidan",6666,6667,this); 以下错误输出...

 11-13 13:12:47.644: W/dalvikvm(204): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
 11-13 13:12:47.644: E/AndroidRuntime(204): Uncaught handler: thread main exiting due to uncaught exception
 11-13 13:12:47.664: E/AndroidRuntime(204): java.lang.NoClassDefFoundError: javax.jmdns.JmDNS
 11-13 13:12:47.664: E/AndroidRuntime(204):     at com.daniel.business.publicchat.PeerAdvertiser.<init>(PeerAdvertiser.java:36)
 11-13 13:12:47.664: E/AndroidRuntime(204):     at com.daniel.business.publicchat.PublicPeer.<init>(PublicPeer.java:60)
 11-13 13:12:47.664: E/AndroidRuntime(204):     at com.chatr.org.PublicChat.onCreate(PublicChat.java:21)
 11-13 13:12:47.664: E/AndroidRuntime(204):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
 11-13 13:12:47.664: E/AndroidRuntime(204):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
 11-13 13:12:47.664: E/AndroidRuntime(204):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
 11-13 13:12:47.664: E/AndroidRuntime(204):     at android.app.ActivityThread.access$2200(ActivityThread.java:119)
 11-13 13:12:47.664: E/AndroidRuntime(204):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
 11-13 13:12:47.664: E/AndroidRuntime(204):     at android.os.Handler.dispatchMessage(Handler.java:99)
 11-13 13:12:47.664: E/AndroidRuntime(204):     at android.os.Looper.loop(Looper.java:123)
 11-13 13:12:47.664: E/AndroidRuntime(204):     at android.app.ActivityThread.main(ActivityThread.java:4363)
 11-13 13:12:47.664: E/AndroidRuntime(204):     at java.lang.reflect.Method.invokeNative(Native Method)
 11-13 13:12:47.664: E/AndroidRuntime(204):     at java.lang.reflect.Method.invoke(Method.java:521)
 11-13 13:12:47.664: E/AndroidRuntime(204):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
 11-13 13:12:47.664: E/AndroidRuntime(204):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
 11-13 13:12:47.664: E/AndroidRuntime(204):     at dalvik.system.NativeStart.main(Native Method)

如果我对上述内容的理解是正确的,那么它在我的 JmDNS 库中存在问题,但是,它正在被补充道。我百分百确定。我导入的 JAR 代码可以在这里找到: https://github.com/Ps2Fino/DSProject -后端

编辑

这似乎是 JmDNS 添加到 Android 的问题,如下所述:http://home.heeere.com/tech-androidjmdns.html 我已尝试按照该指南“重新打包”JmDNS JAR 文件,但我仍然有相同的情况问题。它似乎并不能很好地配合它。

Hopefully my issue isn't too silly but I'm having the following problem...

I'm importing a jar which contains the library JmDNS into my project. My project sets up to handle JmDNS like this...

      setUp();
        try {
            peer = new PublicPeer("Aidan",6666,6667,this);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

     private void setUp(){
        android.net.wifi.WifiManager wifi =
               (android.net.wifi.WifiManager)
                  getSystemService(android.content.Context.WIFI_SERVICE);
        lock = wifi.createMulticastLock("Lock");
            lock.setReferenceCounted(true);
            lock.acquire();
       }

where lock = android.net.wifi.WifiManager.MulticastLock lock; and PublicPeer peer;

When execution reaches peer = new PublicPeer("Aidan",6666,6667,this); the following error outputs...

 11-13 13:12:47.644: W/dalvikvm(204): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
 11-13 13:12:47.644: E/AndroidRuntime(204): Uncaught handler: thread main exiting due to uncaught exception
 11-13 13:12:47.664: E/AndroidRuntime(204): java.lang.NoClassDefFoundError: javax.jmdns.JmDNS
 11-13 13:12:47.664: E/AndroidRuntime(204):     at com.daniel.business.publicchat.PeerAdvertiser.<init>(PeerAdvertiser.java:36)
 11-13 13:12:47.664: E/AndroidRuntime(204):     at com.daniel.business.publicchat.PublicPeer.<init>(PublicPeer.java:60)
 11-13 13:12:47.664: E/AndroidRuntime(204):     at com.chatr.org.PublicChat.onCreate(PublicChat.java:21)
 11-13 13:12:47.664: E/AndroidRuntime(204):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
 11-13 13:12:47.664: E/AndroidRuntime(204):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
 11-13 13:12:47.664: E/AndroidRuntime(204):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
 11-13 13:12:47.664: E/AndroidRuntime(204):     at android.app.ActivityThread.access$2200(ActivityThread.java:119)
 11-13 13:12:47.664: E/AndroidRuntime(204):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
 11-13 13:12:47.664: E/AndroidRuntime(204):     at android.os.Handler.dispatchMessage(Handler.java:99)
 11-13 13:12:47.664: E/AndroidRuntime(204):     at android.os.Looper.loop(Looper.java:123)
 11-13 13:12:47.664: E/AndroidRuntime(204):     at android.app.ActivityThread.main(ActivityThread.java:4363)
 11-13 13:12:47.664: E/AndroidRuntime(204):     at java.lang.reflect.Method.invokeNative(Native Method)
 11-13 13:12:47.664: E/AndroidRuntime(204):     at java.lang.reflect.Method.invoke(Method.java:521)
 11-13 13:12:47.664: E/AndroidRuntime(204):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
 11-13 13:12:47.664: E/AndroidRuntime(204):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
 11-13 13:12:47.664: E/AndroidRuntime(204):     at dalvik.system.NativeStart.main(Native Method)

If my understanding of the above is correct it's having problems located my JmDNS library however, it is being added. I'm 100% sure of it. The code of the JAR which I am importing can be found here: https://github.com/Ps2Fino/DSProject-Backend

EDIT

It appears to be an issue with JmDNS being added to Android as documented here: http://home.heeere.com/tech-androidjmdns.html I've attempted following that guide for "re-jaring" the JmDNS JAR file but I'm still having the same issue. It doesn't appear to be working well with it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

月亮是我掰弯的 2024-12-22 16:08:01

添加 jar 文件的一种方法是从 JmDNS.jar 文件中获取源代码并将其直接添加到您的项目中。我遇到了与您类似的问题,我无法让我的 Android 应用程序正确使用 SourceForge 或 Maven 中的 JmDNS.jar 文件。我只是从 jar 文件中取出所有源文件,将它们添加到我的 Eclipse 项目中,构建它,它的工作就像一个魅力。

我不知道这是否是您想要使用的长期解决方案,但这个解决方案对我有用。

One way that you could go around adding the jar file would be to take the source code from the JmDNS.jar file and add it directly to your project. I was having a issue similar to yours where I could not get my Android application to properly work with the JmDNS.jar file from SourceForge or Maven. I just took all of the source files from jar file, added them to my Eclipse project, built it, and it works like a charm.

I don't know if this would be a long term solution that you would want to use, but this solution worked for me.

烟若柳尘 2024-12-22 16:08:00

我认为 JmDNS 开发人员可能在发布/维护其版本时遇到一些问题,更糟糕的是文档记录很差,您可以从 SourceForge 主页Maven中央仓库,但是,你可以看到同一个版本(最新版本是3.4.1)的jar文件是不同的,来自Maven中央仓库的更干净,可能这就是Heeere在他的页面中所说的关于重装。我总是使用 Maven 构建我的 Android 应用程序,因此从未尝试过 SourceForge 中的应用程序,但是,从 Maven 下载的 jar 文件对我有用。

I think JmDNS developers may have some issues regarding to publish/maintain their release and what even worse is poor documented, you can download jar from both SourceForge home page and Maven central repo, however, you can see that the jar file for the same release (latest version is 3.4.1) are different, the one from Maven central repository is more clean, probably this is what Heeere talked in his page about rejaring. I always use Maven build my Android application and so never tried the one from SourceForge, however, jar file downloaded from Maven works for me.

腹黑女流氓 2024-12-22 16:08:00

由于类尚未加载,可能会发生这种情况。
类 clazz = getClassLoader().loadClass("javax.jmdns.JmDNS");
然后使用反射创建 clazz 类型的对象实例

This might be happening as the class is not loaded yet.
Class clazz = getClassLoader().loadClass("javax.jmdns.JmDNS");
Then use reflection to create instance of object of type clazz

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文