Java - Trouble Shooting

Updated: 2021-11-19

NoSuchMethodError vs ClassNotFoundException

Both are commonly seen at runtime, telling you something is missing, but the fixes are different:

  • java.lang.NoSuchMethodError:
    • cause: the version used to build is different from the one used to run. The internal interfaces may change from the version to version, the "Method" may be available in compile time but not in run time.
    • fix: make sure you are using EXACTLY the same versions in both environment.
  • java.lang.ClassNotFoundException or NoClassDefFoundError:
    • cause: some jar is missing in classpath
    • fix: add the jar to classpath(e.g. java -cp <classpath>)

Got the error message when using Mac OS X + Java 7 ComputerName: ComputerName: nodename nor servname provided, or not known

Solution: add  ComputerName




/usr/bin/ld: cannot find -ljava

Problem: Libraries are missing. -l<sth> means lib<sth>.so. e.g. -ljava means is missing. Check /path/to/jdk1.6.0_26/jre/lib/i386.

In my case: Install 64-bit jdk to a 32-bit machine.

Solution: Install the missing libraries