There are three kinds of actuaries: those who can count, and those who can't.
Piet Souris wrote:java chap02\GameLauncher
using the backslash, as always on windows. But it only worked when I changed the backslash into a forward slash:
java chap02/GameLauncher
Liutauras Vilda wrote:
I'd have expected it to be ran like:
java chap02.GameLauncher <-- I'd say that is a habitual way to execute class when it resides in a package. That works.
I'm surprised it let's execute the way you showed (indeed it works, I tried myself for my curiosity).
There are three kinds of actuaries: those who can count, and those who can't.
Ulvi Mardaliyev wrote:I have run these codes on the same package on IDE, but I did not get such an error. Have you tried on IDE?
Paweł Baczyński wrote:How are you compiling the classes (what command)? How are you running them? What is the directory you compile/run them from? (type cd in the console).
Piet Souris wrote:I wholehartedly agree with Ulvi. An IDE takes away all those command line horrors. But unfortunately, sometimes you have no choice.
Your files are in a package called "chap02". That meeans that GameLauncher will look for a file "chap02\GuessGame.class".
Suppose that you have a directory structure (like I have): d:\javaranch\chap02, and that your 3 java files are in the map chap02.
Now, make sure you are in the map javaranch, then compile GameLauncher with the command:
javac chap02\GameLauncher.java
(note the backslash!)
When that succeeds, you can now run GameLauncher with the command (also from the map javaranch): java chap02/GameLauncher
But take note: I am using Windows 10 powershell, and for half an hour I got exactly the same error as you had. I used the command
java chap02\GameLauncher
using the backslash, as always on windows. But it only worked when I changed the backslash into a forward slash:
java chap02/GameLauncher
And to quote the four Yorkshiremen: tell this to the youth, and they won't believe you
Liutauras Vilda wrote:Once you done what's in post above.
3. Navigate to C:\test directory
4. Execute instruction javac -d . GameLauncher.java GuessGame.java Player.java
Note: -d option means create directory structure specified as package in a current working directory which is denoted by . (dot).
5. Issue instruction java chap02.GameLauncher
Liutauras Vilda wrote:Once you done what's in post above.
3. Navigate to C:\test directory
4. Execute instruction javac -d . GameLauncher.java GuessGame.java Player.java
Note: -d option means create directory structure specified as package in a current working directory which is denoted by . (dot).
5. Issue instruction java chap02.GameLauncher
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |