I’m facing a problem that drives me crazy, I created a java application using netbeans on a windows machine, it contains a plain java class with main method and imports the java.nio as follows.
package testubonto;
import java.nio.*;
import java.nio.BufferOverflowException;
public class Main {
public static void main(String[] args) {
try{
java.nio.file.Path path = java.nio.file.Paths.get(args[0]);
System.out.println(path.toString());
}catch(Exception ex){
System.out.println("Error: " + ex.getMessage());
System.out.println(ex.getStackTrace());
}
}
}
i tested my application and it runs fine on my windows machine. I built it and produced it’s jar file, the problem came when i tried to run this application on my Lubunto machine, I downloaded the jre-7u5.tar.gz, and extracted the folder.
placed the jar file on the root. and when i tried to run the application using terminal by this command.
/home/user/jre1.7.0_05/bin/java -jar “TestUbonto.jar” /home/user
i got the following exception,
Exception in thread “main” java.lang.NoSuchMethodError:
java.nio.file.Paths.get
what should i do?? 🙂
Thanks in advance,
The NoSuchMethodException occurs when the jar file used for building differs from the one used for executing.
The jar used for building , supplies the method that is required by your code. So there wont be any compilation error and the binary is prepared correctly.
But when you run the same code by giving a wrong version the same jar in the classpath, it will give the above exception.
Verify the jars you are using .