Forums Register Login

Code problem or logic problem ?

+Pie Number of slices to send: Send
.....i just got error on run time .... please ...i don't understand why ??? and i can't have all these classes as public .... Compiler just start shouting at me ...if i do it.



Error:
---------- Run Java Class ----------
java.lang.NoClassDefFoundError: GameLauncher
Exception in thread "main"
Output completed (0 sec consumed) - Normal Termination
+Pie Number of slices to send: Send
You misspelled the name of the main class as "GameLanucher".
+Pie Number of slices to send: Send
okay...and y can't i make all the class as public as mentioned K&B book in chapter 2
+Pie Number of slices to send: Send
Each source file can only have one public class -- it's just the rule. If you need more than one public class, put each in its own file named X.java, where X is the name of the class.
+Pie Number of slices to send: Send



Each source file can only have one public class -- it's just the rule.



yes! i got it.... but the thing is ....it takes public for GameLanucher class and not for other two why is that it only accepts GameLanucher as public
+Pie Number of slices to send: Send
As I implied above, a public class X has to be in a file named X.java.
+Pie Number of slices to send: Send
i need only Player to be public but it's not taking ...
+Pie Number of slices to send: Send
It feels like only public static void main() method , class should be public ...if others try to be ...compiler screams....
+Pie Number of slices to send: Send
 

Arun Giridharan wrote:i need only Player to be public but it's not taking ...



You need to move Player into a file named "Player.java" before you can mark it as "public".
+Pie Number of slices to send: Send
Thanks ..... i like to know why do they do that ....means what is the real purpose of this rule .......
+Pie Number of slices to send: Send
It makes it far easier to write a Java compiler. If classes are in a file named after the class, then the compiler can easily find the code for class B while it's compiling class A which mentions B. Since only public classes are accessible outside of their own package, the rule is only enforced for public classes, but it's actually a good rule for any class that's going to be used in code that appears in more than one file.

Newbies fuss over this kind of thing, but realize that any real Java application contains hundreds and usually thousands of classes; putting them in files names after the class makes them much easier for people to find, too!
+Pie Number of slices to send: Send
wow! cool ...but in the chapter 2 they mentioned about .jar file ,put the application into it and run(somehow) ...cud you please ...explain how to do that ! !
+Pie Number of slices to send: Send
This page in our FAQ has some info about jar files, and pointers to more. Note that we've been talking about source code, but jar files are for holding class files, not source.
I'm gonna teach you a lesson! Start by looking at this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 918 times.
Similar Threads
Head First Java Book, Chapter 2
GuessGame Errors From Head First Java
Exceptation in thread "main" java.lang.NoSuchMethodError: main
Very new to java
Head First Java: Guessing Game infinite look
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 07:23:57.