• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can't get MyFirstApp working

 
Richard Mateosian
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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"
 
Richard Mateosian
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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"
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic