Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NoSuchMethodError for Class File Method toPath()

I'm attempting to copy the file StandardQuestions.csv to a new filename with the following code:

String standardQuestions = "StandardQuestions.csv";
if(new File(standardQuestions).exists()){
    try{
        Path source = new File(standardQuestions).toPath();
        Path dest = new File(filename).toPath();
        Files.copy(source,dest);
    }
     catch(java.io.IOException e){JOptionPane.showMessageDialog(this,"Error: Input/Output exception.");}
}

I get an error thrown on the line Path source = new File(standardQuestions).toPath(); My error message is NoSuchMethodError, method toPath not found in class File. How could the File class not have this method? The program runs correctly on 3-4 machines, but for one user, it always throws this error. Any idea what's causing this? Is there any additional information needed to answer this question?

like image 359
user984165 Avatar asked Apr 21 '26 19:04

user984165


2 Answers

Since Path and toPath() are relatively recent additions to the Java library (they've been added in Java 7), I'd make sure you are using the same version of Java across the machines.

like image 175
NPE Avatar answered Apr 24 '26 09:04

NPE


The first thing that comes up is that one user is running a significantly different version of Java. It might be particularly old or non-standard (GNU Classpath).

Have your user upgrade their Java installation version.

like image 20
Mark Robinson Avatar answered Apr 24 '26 08:04

Mark Robinson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!