Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

first program, first error  RSS feed

 
Krep Lock
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i'm trying to compile and run a simple program directly from a command line (win2000):


public class MyFirstApp {


public static void main (String[] args) {
System.out.println("hello, world");
}

}


1) save as MyFirstApp.java
2) javac MyFirstApp.java
3) java MyFirstApp

produces the following:

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


is there some linker problem here?
 
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
Hi,

Welcome to JavaRanch!

The problem is that you've got the CLASSPATH environment variable (which java.exe uses to find class files) set to a value other than the default, and your value doesn't include "." (dot), the current directory. The very best CLASSPATH setting for newbie and guru alike, really, is to have it not set to anything, but since perhaps some random software has set it for you, it may be best not to meddle with it.

Therefore, use the command-line switch to specify that the classpath should include the current directory and things should be fine:

java -cp . HelloWorldApp

That's "java space dash cp space dot space HelloWorldApp".
 
Krep Lock
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
exactly so. thanks for the help.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!