1

Cannot compile or run the Hangman console application I created in Eclipse. It is in my ~/Documents folder on my mac in a package called hangman. It doesn't see the two classes Game and Prompter that I created. I've tried using -cp but I'm not sure I am doing it right. It doesn't the ways I've tried it. Any help?

HoltnetMacbookAir:hangman godmanliving$ javac -classpath . Hangman.java
Hangman.java:20: error: cannot find symbol
    Game game = new Game(args[0]);
    ^
symbol:   class Game
location: class Hangman
Hangman.java:20: error: cannot find symbol
    Game game = new Game(args[0]);
                    ^
symbol:   class Game
location: class Hangman
Hangman.java:21: error: cannot find symbol
    Prompter prompter = new Prompter(game);
    ^
symbol:   class Prompter
location: class Hangman
Hangman.java:21: error: cannot find symbol
    Prompter prompter = new Prompter(game);
                            ^
symbol:   class Prompter
location: class Hangman
4 errors
Jason Holt
  • 83
  • 9

1 Answers1

1

You need to specify all files that need to be compiled.

It looks like in your case it would be something like this:

javac -classpath . Hangman.java Game.java Prompter.java

References:

how to compile multiple java source files in command line

http://www.codejava.net/java-core/tools/using-javac-command

Community
  • 1
  • 1
Daniel Nugent
  • 43,104
  • 15
  • 109
  • 137
  • 1
    For the sake of the OP's clarity, the `.` is important because the javac command needs to be explicitly directed to look in the current directory for .class files. – Chetan Kinger Mar 26 '15 at 17:39
  • Following that up with `java -classpath . Hangman` produces the error: `Error: Could not find or load main class Hangman`. This is way more frustrating than I expected. – Jason Holt Mar 26 '15 at 20:11
  • @JasonHolt You can only run a class using the java command if it contains a `public static void main(String []args)` method – Chetan Kinger Mar 27 '15 at 06:05
  • @bot thanks for the response. My Hangman class has that main method. Is there anything else I could be missing? Should I open a new topic with a question about it and post my code? – Jason Holt Apr 02 '15 at 13:34
  • @JasonHolt Take a look at this link: http://stackoverflow.com/questions/12909767/how-is-noclassdeffounderror-thrown/12909804#12909804 If you are still not able to run, open up a new question and post your code, I'll take a look. – Daniel Nugent Apr 02 '15 at 15:30