This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Can't get MyFirstApp working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Can Watch "Can New topic
Author

Can't get MyFirstApp working

EJ Amber
Greenhorn

Joined: Aug 12, 2005
Posts: 8
I am reading Head First Java and am at page 9, trying to get the first program running. I have typed in the program as follows:

public class MyFirstApp {

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



Running javac and java, I see the following:

c:\JavaPlay\ejprog>javac MyFirstApp.java

c:\JavaPlay\ejprog>java MyFirstApp
Exception in thread "main" java.lang.NoClassDefFoundError: MyFirstApp

c:\JavaPlay\ejprog>


The files are there:

Directory of c:\JavaPlay\ejprog

08/11/2005 11:20 PM <DIR> .
08/11/2005 11:20 PM <DIR> ..
08/12/2005 12:00 AM 450 MyFirstApp.class
08/11/2005 11:26 PM 172 MyFirstApp.java
2 File(s) 622 bytes
2 Dir(s) 3,420,708,864 bytes free


What am I doing wrong?

Thanks for your help.


EJ
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
What happens when you type "java -version"? Is it the version you expect?

What do you get when you type "echo %CLASSPATH%" (without quotes) at the command prompt?

If the CLASSPATH is set, you can override it by using the command:
"java -classpath . MyFirstApp"


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
EJ Amber
Greenhorn

Joined: Aug 12, 2005
Posts: 8
The version is OK. Your classpath override made it work.

The CLASSPATH variable was set, but did not include a dot for the current directory. I added the dot as the first directory in CLASSPATH, and now it works as expected.

Thank you very much!

EJ


Originally posted by Barry Gaunt:
What happens when you type "java -version"? Is it the version you expect?

What do you get when you type "echo %CLASSPATH%" (without quotes) at the command prompt?

If the CLASSPATH is set, you can override it by using the command:
"java -classpath . MyFirstApp"
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can't get MyFirstApp working
 
Similar Threads
Trouble with HelloWorld
Newbie: Run-time error
InvalidMappingException
Exception in thread "main" java.lang.NoClassDefFoundError: MyFirstApp. Please help basic issue