Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

First dumb question

 
Steve Janvrin
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just started using the Head First Java book to learn Java. I created my source file using the code from page 7. It is:

public class MyFirstApp {

public static void main (String[] args) {
System.out.println ("I Rule!");
System.out.println ("The World");
}
}

I don't see any errors, but I get the following when I attempt to run it:

Exception in thread "main" java.lang.NoClassDefFoundError: MyFirstApp

Please advise.

Also - am I in the right place for questions this basic?

Steve Janvrin.
 
Joe Ess
Bartender
Posts: 9302
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Java Ranch. So many people have this problem, it made the FAQ. And yes, you are in the right place to ask the most very basic questions.
Good Luck!
 
K Riaz
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try

java -cp . MyFirstApp
 
Matt Fielder
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what did you save the file as?
 
Steve Janvrin
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I saved the file as .java. I'll try the suggestions and post again if I still have problems. Thanks for the quick replies.

Steve.
 
Matt Fielder
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry I should have typed more.
One of my early mistakes was that I didn't know that the file name and class name had to be the same.
 
Steve Janvrin
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Matt - thanks for the clarification. I did indeed have the name of the file and the class name as the same thing.

I got the program to run successfully using Kashif's approach. Thanks again for the help.

Steve.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic