This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I would be grateful if I can get some help with this problem.
How do I run a simple application of 3 classess linked together in JCreator. Here's my problem: I have 3 classess - Player, GuessGame, and Game. In the Game class, where the main method is, I create a new object from the class GuessGame and call a method from the same class; In the GuessGame class, I create new Players (p1, p2 and p3) and call a method from the Player class. The only class that compiles is the Player class. When I run the Game class (it has the main method), I get errors that says "cannot find symbol" - the GuessGame class cannot be seen. A similar type of problem is encountered when I run the GuessGame class - it cannot find the Player class.
How do I set up JCreator to be able to see and run different classes in one application?
Do you have package names in your classes? If so, one of the classes may be dependent on another. In which case compile the dependency first.
Otherwise, for something like the GuessGame, simply take out the package names. And any import statements referring to the other two classes.
Joined: Jul 22, 2009
Thanks for your response.
Yes the classes are dependent on each other and I have tried compiling the dependency one first, but it still does not work. Any more ideas?
Joined: Oct 13, 2005
As before: do you have package names in the classes? The guess game in the book (I have the 2nd edition, where it is page 39-40) doesn't have package names, but I think the version you can download does have package names, so behaves differently. Use JCreator to save those three files in a new folder somewhere, with any package names and any import statements deleted. You now have new copies of those three files in a folder, maybe My Documents\java\guessgame. My Documents/java is a good sort of file to create because when you open a Windows command prompt it starts in My Documents as a default. [Yes, I know you are on Windows because JCreator only works on Windows.]
Open a command line (start---all programs---accessories---command prompt or similar, with the black square icon).
Use a command to navigate to your guessgame directory: cd java\guessgame Use these commands to execute the game
\my documents\java\guessgame:>javac GameLauncher.java
\my documents\java\guessgame:> java GameLauncher
I'm thinking of a number between 0 and 9 . . .
Number to guess is 2
I'm guessing 2
I'm guessing 4
I'm guessing 9
Player one guessed 2
Player two guessed 4
Player three guessed 9
We have a winner!
Player one got it right? true
Player two got it right? false
Player three got it right? false
Game is over.
I have copied the three classes out of the book with only some minor capitalisation and formatting changes, so you can copy and paste it and have code free from spelling mistakes.Note the names of the files must be spelt exactly right, otherwise it won't work. Click on the "view plain" links before copying and pasting.
Joined: Jul 22, 2009
Thanks Campbell. Will try your suggesstions.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: Running an application of 3 classess in JCreator