2016-10-14 55 views
0

我正在尝试开发巡航控制系统的Java应用程序。但是我没有这样的文件异常问题。因为我在java编码方面有点新。我不知道为什么会出现这个问题。我的代码是 -Java显示错误NoSuchFileException

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()); 
    } 
} 

而且我发现的错误是 -

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) 

我的主要方法是 -

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

回答

-1

您没有传递任何参数到主方法运行程序时。

你还可以添加你如何运行这个。

+0

@kushagra_mittal我hav修改了我的问题,并给出了主要方法 – ktina51

+0

你使用eclipse或命令行来运行这个吗? –

+0

我试图用eclipse运行这个 – ktina51

0

程序参数文本框中,您当前有“commandLineArgs [0]”。您需要将“commandLineArgs [0]”更改为包含输入状态的文件的路径。类似于“/数据/输入状态”。

enter image description here

0

我的主要方法是:

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

不,它不是。您正在通过"commandLineArgs[0]"作为参数。你的意思是commandLineArgs[0],没有引号。