0

I am trying to develop a java application for cruise control system. But I am having a problem in no such file exception. As I am little bit new in java coding. I am not sure why this problem is occurring. My Code is-

 public static void main(String[] commandLineArgs) throws IOException {
    Path input_path = Paths.get(commandLineArgs[0]);
    List<InputState> input_states = StateInput.input_states_from_file(input_path);
    Timer timer = new Timer(new CruiseControlSystem());
    List<OutputState> output_states = timer.pulse_from_input(input_states);
    for (OutputState s : output_states){
        System.out.println(s.format());
    }
}

And the Error I found is -

Exception in thread "main" java.nio.file.NoSuchFileException: commandLineArgs[0]
at sun.nio.fs.WindowsException.translateToIOException(Unknown Source)
at sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source)
at sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source)
at sun.nio.fs.WindowsFileSystemProvider.newByteChannel(Unknown Source)
at java.nio.file.Files.newByteChannel(Unknown Source)
at java.nio.file.Files.newByteChannel(Unknown Source)
at java.nio.file.spi.FileSystemProvider.newInputStream(Unknown Source)
at java.nio.file.Files.newInputStream(Unknown Source)
at java.nio.file.Files.newBufferedReader(Unknown Source)
at java.nio.file.Files.readAllLines(Unknown Source)
at StateInput.input_states_from_file(StateInput.java:31)
at CommandLine.main(CommandLine.java:23)

My Main Method is -

public static void main(String[] commandLineArgs) throws IOException {
    Path input_path = Paths.get(commandLineArgs[0]);
    List<InputState> input_states = StateInput.input_states_from_file(input_path);
    Timer timer = new Timer(new CruiseControlSystem());
    List<OutputState> output_states = timer.pulse_from_input(input_states);
    for (OutputState s : output_states){
        System.out.println(s.format());
     }
 }

image of run configuration

ktina51
  • 25
  • 1
  • 8

3 Answers3

0

In the Program Arguments textbox you currently have "commandLineArgs[0]". You need to change "commandLineArgs[0]" to the path to your file containing the input states. Something like "/data/input-states".

enter image description here

StvnBrkdll
  • 3,924
  • 1
  • 24
  • 31
0

My main method is:

Path input_path = Paths.get(commandLineArgs[0]);

No it isn't. You are passing "commandLineArgs[0]" as the argument. You mean commandLineArgs[0], without the quotation marks.

user207421
  • 305,947
  • 44
  • 307
  • 483
-1

You are not passing any arguments to main method while running the program.

Can you also add how are you running this.

kushagra mittal
  • 343
  • 5
  • 17