Bug 633 - FileNotFoundException when I run the built JAR file of our project
Summary: FileNotFoundException when I run the built JAR file of our project
Status: CONFIRMED
Alias: None
Product: Group14-Pacman
Classification: Unclassified
Component: Game (show other bugs)
Version: 0.0.2
Hardware: PC Windows
: --- enhancement
Assignee: YANG Tianxia
URL:
Depends on:
Blocks:
 
Reported: 2021-12-03 16:26 HKT by YANG Tianxia
Modified: 2021-12-03 16:26 HKT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description YANG Tianxia 2021-12-03 16:26:50 HKT
Description: I built a runnable JAR file of our PacMan project (excluding the Graphics part, because it's not shown in the GitHub repo github.com/aleksa006670/PacMan_Version_2.git) using Eclipse IDE. After a JAR file is generated, I tried to run the JAR file with the command line:

         java -jar <Name of the JAR file>.jar

And the program raised FileNotFoundExceptions after I inputted my name and game difficulties.

Following is the output (with exceptions) of the program:
==========================================================
Please, specify your name:
Robbin <<<<<<<<<<<<<<<<<This line is my input
Please specify the difficulty (Easy, Medium, Hard):
Easy   <<<<<<<<<<<<<<<<<This line is my input
java.io.FileNotFoundException: src\Resource\easyGhostData.txt (The system cannot find the specified path)
        at java.base/java.io.FileInputStream.open0(Native Method)
        at java.base/java.io.FileInputStream.open(FileInputStream.java:219)
        at java.base/java.io.FileInputStream.<init>(FileInputStream.java:157)
        at java.base/java.util.Scanner.<init>(Scanner.java:639)
        at Game.Ghost.initGhosts(Ghost.java:19)
        at Game.Game.gameInit(Game.java:38)
        at Game.Main.main(Main.java:18)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:61)
java.io.FileNotFoundException: src\Resource\easyPacmanData.txt (The system cannot find the specified path)
        at java.base/java.io.FileInputStream.open0(Native Method)
        at java.base/java.io.FileInputStream.open(FileInputStream.java:219)
        at java.base/java.io.FileInputStream.<init>(FileInputStream.java:157)
        at java.base/java.util.Scanner.<init>(Scanner.java:639)
        at Game.PacMan.initPacMan(PacMan.java:27)
        at Game.Game.gameInit(Game.java:39)
        at Game.Main.main(Main.java:18)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:61)
java.io.FileNotFoundException: src\Resource\easyMaze.txt (The system cannot find the specified path)
        at java.base/java.io.FileInputStream.open0(Native Method)
        at java.base/java.io.FileInputStream.open(FileInputStream.java:219)
        at java.base/java.io.FileInputStream.<init>(FileInputStream.java:157)
        at java.base/java.util.Scanner.<init>(Scanner.java:639)
        at Game.Maze.generateMaze(Maze.java:145)
        at Game.Maze.initMaze(Maze.java:43)
        at Game.Game.gameInit(Game.java:40)
        at Game.Main.main(Main.java:18)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:61)
Maze map file src/Resource/easyMaze.txt not found
Algorithm file src/Resource/easyAlgorithmData.txt not found
Exception in thread "main" java.lang.reflect.InvocationTargetException
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:61)
Caused by: java.lang.NullPointerException
        at Game.Game.isGameOver(Game.java:267)
        at Game.Main.main(Main.java:25)
        ... 5 more
==========================================================

Here are the steps that I use to build a runnable JAR file in Eclipse:
(1) Open our pacman project in Eclipse IDE
(2) Open the "Package Explorer" perspective. Navigate to the top item "Pac-man [PacMan_Version_2 main]".
(3) Left click on it and select "Export..."
(4) In the "Select" dialog, expand the folder in this way: "Java" > "Runnable JAR File". Choose "Runnable JAR File" and click "Next" to proceed
(5) In the "Runnable JAR File Specification" dialog, select "Main - Pac-man" as "Launch configuration". And specify a directory to output the generated JAR file. And for "Package handling" choose the option "Package required libraries into generated JAR". Let the other fileds remain as default and click "Finish" button.
(6) After the JAR file is created, I used the command mentioned above, which is 
     java -jar <Name of the JAR file>.jar
to execute it as runnable JAR file.