-6

When I run the code in eclipse it runs perfectly fine, but when i run it through the command line it has an error, I have looked around but could not find an answer that works. the error I get is below:

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

Thanks in advance!

  • the jvm is looking for src\data\pokemon.csv from its working directory. It seems the file is located inside the eclipse project. This has been asked before. Keep on searching – bichito Jun 29 '17 at 01:56

1 Answers1

-1

I assume you are starting the program from the Builds directory - not the project root. Therefore the path src\data\pokemon.csv can't be resolved. You have to either copy the jar to the project root or start the program from the project root dir with java -jar Builds\v1.0.jar

fhossfel
  • 2,041
  • 16
  • 24
  • I built the jar as a runnable jar and it has the files contained in it. [Jar File Structure](http://imgur.com/a/ajilV) – Stephen Toth Jun 29 '17 at 02:50
  • You can't read from a jar using a FileReader. It works under Eclipse because the pokemon.csv is still available in the src directory - so your program uses that. If you want to read a file from a jar you will have to use the classloader's getResourceAsStream method. And you will have to remove the "src" from the path. So it is just this.getClass().getResourceAsStream("data/pokemon.csv") If you want to use a reader on that you will have to use the InputStreamReader in your read() method. new InputStreamReader(this.getClass().getResourceAsStream("data/pokemon.csv")) – fhossfel Jun 29 '17 at 08:40