1

I have the following code:

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.Path;
public class debugImageMain {
    public static void main() throws IOException {
        Path path = Paths.get("path/to/file");
        byte[] data = Files.readAllBytes(path);
    }
}

But when I run I get:

Exception in thread "main" java.lang.NoSuchMethodException: pdc.conversor.debugImageMain.main([Ljava.lang.String;) at java.lang.Class.getMethod(Class.java:1786)

javac -version gives: javac 1.8.0_60 and I have java VERSION 8 Update 91.

IntelliJ tell me java.nio.file imports are underlined in red and says "Usages of API which isn't available at the configured language level.

Any help please???

J Agustin Barrachina
  • 3,501
  • 1
  • 32
  • 52
  • 6
    no it work your main method is not correct ;) it should be `public static void main(String[] args) throws IOException {` – Youcef LAIDANI Jun 03 '17 at 20:07
  • And in "Project structure", you probably selected Java 6 (or lower) as your language level, instead of Java 8, hence the warning. – JB Nizet Jun 03 '17 at 21:18
  • Please post the entire error message – Code-Apprentice Jun 03 '17 at 23:34
  • The stack trace shows clearly that `java.nio.file` has exactly nothing to do with it. – user207421 Jun 04 '17 at 00:04
  • *"java.nio.file not workin in java 8"* ... Java is 20 years old. Its libraries have been continuously developed for many years. It requires a peculiar form of arrogance to conclude that an error in a program you have written must reside in the Java libraries ... rather than in the code you have written. – scottb Jun 04 '17 at 00:31
  • @scottb very hepfull.... I didn't write "java.nio.file not workin in java 8 because Java is wrong" you just concluded I thought it was java fault... I wrote it that way because all over the internet it says java.nio.file doesn't work in java 6 or lower... so to avoid people to tell me that my java version was old... because it was java 8 then the problem couldn't be java... – J Agustin Barrachina Jun 04 '17 at 18:02

2 Answers2

1

Java required the main method to be definded correctly which is the entry point to run the app.

Try:

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.Path;
public class debugImageMain {
    public static void main(String[] args) throws IOException {
        Path path = Paths.get("path/to/file");
        byte[] data = Files.readAllBytes(path);
    }
}
Minh Kieu
  • 475
  • 3
  • 9
1

The problem is not with java.nio.file, the problem is in the definition of main signature.

  • The only way to running a program in Java is with the specific public static void main (String [] args) signature.

To fix your current statement, change this:

public static void main() throws IOException {

For this:

public static void main (String[] args) throws IOException {

Check it out these entries first, and second

JUAN CALVOPINA M
  • 3,695
  • 2
  • 21
  • 37
  • It worked... as IntelliJ underlined in red the java.nio.file it led me to believe the problem was there... But it was a complicatedly different issue. Thank you very much. – J Agustin Barrachina Jun 04 '17 at 22:27