2016-10-14 51 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],沒有引號。