• Post Reply Bookmark Topic Watch Topic
  • New Topic

Code problem or logic problem ?  RSS feed

 
Arun C. Giridharan
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
.....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
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You misspelled the name of the main class as "GameLanucher".
 
Arun C. Giridharan
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
okay...and y can't i make all the class as public as mentioned K&B book in chapter 2
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Arun C. Giridharan
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



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
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As I implied above, a public class X has to be in a file named X.java.
 
Arun C. Giridharan
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i need only Player to be public but it's not taking ...
 
Arun C. Giridharan
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It feels like only public static void main() method , class should be public ...if others try to be ...compiler screams....
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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".
 
Arun C. Giridharan
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks ..... i like to know why do they do that ....means what is the real purpose of this rule .......
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Arun C. Giridharan
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ! !
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!