项目在eclipse中运行,但不在命令行中运行:找不到文件异常

时间:2017-06-29 01:53:15

标签: java eclipse file runtime-error

当我在eclipse中运行代码时,它运行得非常好,但是当我通过命令行运行它有一个错误时,我已经环顾四周但找不到有效的答案。我得到的错误如下:

C:\Users\Name\Documents\Java Projects\PokemonBattle\Builds>java -jar v1.0.jar

java.io.FileNotFoundException: src\data\pokemon.csv (The system cannot find the path specified)
        at java.io.FileInputStream.open0(Native Method)
        at java.io.FileInputStream.open(Unknown Source)
        at java.io.FileInputStream.<init>(Unknown Source)
        at java.io.FileInputStream.<init>(Unknown Source)
        at java.io.FileReader.<init>(Unknown Source)
        at pokemonFramework.ReadCSV.read(ReadCSV.java:30)
        at pokemonFramework.Pokemon.getPkmnInfo(Pokemon.java:174)
        at main.PokemonBattleClient.<init>(PokemonBattleClient.java:64)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)

        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
        at java.lang.reflect.Constructor.newInstance(Unknown Source)
        at java.lang.Class.newInstance(Unknown Source)
        at processing.core.PApplet.runSketch(PApplet.java:10453)
        at processing.core.PApplet.main(PApplet.java:10279)
        at processing.core.PApplet.main(PApplet.java:10261)
        at main.PokemonBattleClient.main(PokemonBattleClient.java:89)
java.lang.NullPointerException
        at pokemonFramework.ReadCSV.read(ReadCSV.java:47)
        at pokemonFramework.Pokemon.getPkmnInfo(Pokemon.java:174)
        at main.PokemonBattleClient.<init>(PokemonBattleClient.java:64)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)

        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
        at java.lang.reflect.Constructor.newInstance(Unknown Source)
        at java.lang.Class.newInstance(Unknown Source)
        at processing.core.PApplet.runSketch(PApplet.java:10453)
        at processing.core.PApplet.main(PApplet.java:10279)
        at processing.core.PApplet.main(PApplet.java:10261)
        at main.PokemonBattleClient.main(PokemonBattleClient.java:89)

File structure of JAR

提前致谢!

1 个答案:

答案 0 :(得分:-1)

我假设您从Builds目录启动程序 - 而不是项目根目录。因此无法解析路径src \ data \ pokemon.csv。您必须将jar复制到项目根目录,或者使用java -jar Builds \ v1.0.jar从项目根目录启动程序