Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

basic questin

 
Andrei Pop
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm trying to run a simple program:

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

It compiles fine. When I run it I got this:

E:\work\java>java Hello
Exception in thread "main" java.lang.NoClassDefFoundError: Hello

I don't know what could be.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Andrei,

Welcome to JavaRanch!

The problem is that, knowingly or unknowingly, you've set your CLASSPATH environment variable (which Java uses to find .class files), and the value you've set it to does not include "." (dot, meaning the current directory). The best thing to do is to not have CLASSPATH set at all, but if you must set it, then include "." as an entry.

See the CLASSPATH page in the JavaRanch FAQ for more information.
 
Andrei Pop
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you!

I read Sun's tutorial on running the first cup of Java and they didn't say anything about setting a CLASSPATH. But, I have a CLASSPATH variable already set by another application. Therefore, I added the . (dot) and everything works fine.

Thanks again!

And I can't notice how quick the answers are on Javaranch.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic