-2

I have been trying to find why my program isn't running from the terminal. But it keeps saying it can't find the packages/packages do not exist when they do. Here are some pictures. Here Is one 1 here is the other one 2 Here is the last one 3

This is the code that I get from the errors:

PS C:\Users\alexg\IdeaProjects\MonstersVersusHeroes\src> java mvh\Main.java world.txt log.txt 12345
mvh\Main.java:3: error: package mvh.util does not exist
import mvh.util.Reader;
               ^
mvh\Main.java:4: error: package mvh.world does not exist
import mvh.world.World;
                ^
mvh\Main.java:126: error: cannot find symbol
    private static void runSimulation(World world) {
                                      ^
  symbol:   class World
  location: class Main
mvh\Main.java:46: error: cannot find symbol
        Menu.setup(fileLog);
        ^
  symbol:   variable Menu
  location: class Main
mvh\Main.java:47: error: cannot find symbol
        Menu.println("Arguments: "+ Arrays.toString(args));
        ^
  symbol:   variable Menu
  location: class Main
mvh\Main.java:48: error: cannot find symbol
        World world = Reader.loadWorld(fileWorld);
        ^
  symbol:   class World
  location: class Main
mvh\Main.java:48: error: cannot find symbol
        World world = Reader.loadWorld(fileWorld);
                      ^
  symbol:   variable Reader
  location: class Main
mvh\Main.java:97: error: cannot find symbol
            if (Menu.checkYes()) {
                ^
  symbol:   variable Menu
  location: class Main
mvh\Main.java:129: error: cannot find symbol
            Menu.println(message);
            ^
  symbol:   variable Menu
  location: class Main
mvh\Main.java:130: error: cannot find symbol
            if (Menu.continueSimulation()) {
                ^
  symbol:   variable Menu
  location: class Main
mvh\Main.java:137: error: cannot find symbol
        Menu.println(message);
        ^
  symbol:   variable Menu
  location: class Main
11 errors
error: compilation failed

And the error at the end says error compilation failed.

As you can clearly see the program does have the packages where they need to be.

If someone can help to find out what's wrong and how I can run my program.

Rafael G
  • 1
  • 2
  • How are you compiling your files when you try with the terminal? – Lino Mar 11 '22 at 12:40
  • 1
    Code and error messages are all text. Please post them as well formatted/indented text, instead of screenshots. – GhostCat Mar 11 '22 at 12:41
  • if in IntelliJ you rightclick on the Main file and select "Run 'Main'" what happens? – Steve Bosman Mar 11 '22 at 13:08
  • It runs as expected, since my program is just supposed to run from the terminal. When I run it from the Main File it says: "C:\Users\alexg\IdeaProjects\MonstersVersusHeroes\out\production\MonstersVersusHeroes mvh.Main Program requires 2 arguments! Usage: Main " Which is what I expect it to do. But when I run it from the terminal even when I don't pass the required 2 arguments it gives me the same 11 errors. – Rafael G Mar 11 '22 at 13:14
  • I suggest that you read the [java command documentation](https://docs.oracle.com/en/java/javase/17/docs/specs/man/java.html) as well as this Web page from Oracle's Java tutorials: ["Hello World!" for Microsoft Windows](https://docs.oracle.com/javase/tutorial/getStarted/cupojava/win32.html) – Abra Mar 19 '22 at 08:42
  • Take a look at https://stackoverflow.com/questions/12620369/how-does-java-import-work and also how `classpath` works and jar files work. – Richard Chambers Mar 22 '22 at 03:00
  • https://stackoverflow.com/questions/17140512/how-to-compile-multiple-java-files-when-there-are-java-files-in-other-packages – wovano Mar 22 '22 at 06:54

1 Answers1

1

Multifile projects need compiling first before you run them.

In the terminal move up to the src directory and try running with

javac mvh/Main.java
java mvh.Main world.txt log.txt

Alternatively, let intellij compile it (it probably puts the classes files in a folder called out/production/{your project name}), and run main from there.

Steve Bosman
  • 2,599
  • 1
  • 25
  • 41