Java – Android Exception : ‘java.lang.NoClassDefFoundError: javax.jmdns.JmDNS’

Android Exception : ‘java.lang.NoClassDefFoundError: javax.jmdns.JmDNS’… here is a solution to the problem.

Android Exception : ‘java.lang.NoClassDefFoundError: javax.jmdns.JmDNS’

Hopefully my question isn’t too stupid, but I’m having the following problem….

I’m importing a jar containing library JmDNS into my project. My project is set 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;

When executed to peer = new PublicPeer("Aidan",6666,6667,this); The following error is printed….

 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, then I have a problem with my JmDNS library, however, it is being added. I’m 100% sure. The code for the JAR I’m importing can be found here: https://github.com/Ps2Fino/DSProject-Backend

Edit

This seems to be an issue with adding JmDNS to Android, as follows: http://home.heeere.com/tech-androidjmdns.html I’ve tried “recompressing” JmDNS JAR files following that guide and I’m still having the same issue. It doesn’t seem to be working.

Solution

I think JmDNS developers may have some issues with publishing/maintaining their versions, and worse there is no record, you can download jar from both websites SourceForge home page and Maven central repo However, you can see that the jar files for the same version (the latest version is 3.4.1) are different and cleaner from the Maven repository, which is probably what Heeere talked about about rejaring in his page. I always build my Android apps with Maven, so I’ve never tried an app from SourceForge, however, the jar file downloaded from Maven worked for me.

Related Problems and Solutions