Sunday, April 1, 2012

Installing FANN on Java project and NativeLibrary.loadLibrary problems with 32bit/64bit

If you try to install FANN and get it working with a Java project you might run into a few problems. The whole process is explained on the fannj (the Java binding) project's wiki but not in great detail.

Here is what you need to do:

  1. Get fannj
  2. Store it somewhere and add the jar to your project.
  3. Get FANN
  4. Extract it somewhere.
  5. Either :
    * copy the fannfloat.dll to System32
    * add the following line before you try to use FANN:
     System.setProperty("jna.library.path", [fannfloat.dll dir path]);

Solutions to problems:

No Java Native 
"Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/jna/Platform"
Solution: Download the JNA and add the jar to your project.

Can' find the FANN library
Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'fannfloat': The specified module could not be found.
Add the following code after you set the JNA library path, run it:

System.out.println( System.getProperty("jna.library.path") ); //maybe the path is malformed
File file = new File(System.getProperty("jna.library.path") + "fannfloat.dll");
System.out.println("Is the dll file there:" + file.exists());
You can fix the problems if something is wrong with the first two messages easily.
If the code fails with this message:
Exception in thread "main" java.lang.UnsatisfiedLinkError: [ddl path]: Can't load IA 32-bit .dll on a AMD 64-bit platform
then you are probably running a 64bit Java SDK while fannfloat.dll is 32bit. The solution for me was installing additional 32bit Java SDK and choosing it in the build path for my project.


  1. Just added this helpful information to the FannJ wiki page. If you can think of other ways FannJ can be improved, let us know. Thanks!

  2. Great, glad I could help. :)

    ATM I got nothing, but I'll be sure to contact you guys if something comes to my mind.

  3. This comment has been removed by a blog administrator.

  4. This comment has been removed by the author.

  5. this is only for PC, right??

    can i run this fannj on device android using eclipse??

  6. Огромное спасибо за помощь! )