Please register or login. There are 0 registered and 1237 anonymous users currently online. Current bandwidth usage: 326.30 kbit/s December 12 - 04:48pm EST 
Hardware Analysis
      
Forums Product Prices
  Contents 
 
 

  Latest Topics 
 

More >>
 

    
 
 

  You Are Here: 
 
/ Forums / Programming /
 

  java.lang.NoClassDefFoundError: in a Hello World program! Help! 
 
 Author 
 Date Written 
 Tools 
Continue Reading on Page: 1, 2, Next >>
Nathan Daniels Aug 12, 2006, 01:29pm EDT Reply - Quote - Report Abuse
Private Message - Add to Buddy List

Edited: Aug 12, 2006, 02:03pm EDT

Replies: 30 - Views: 15423
I have a file called Hello.java. The exact text inside this file is...

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

And every time I type this into command prompt...

javac Hello.java

I get this error...

Exception in thread "main" java.lang.NoClassDefFoundError: hello/java

Now this is just a very basic hello world program! It works fine when I run it from Dr. Java, the program i use to write Java. What is going on?


--------
"The more we sweat in peace, the less we bleed in war."
-Patton
Want to enjoy fewer advertisements and more features? Click here to become a Hardware Analysis registered user.
Aug 12, 2006, 02:07pm EDT Reply - Quote - Report Abuse
Private Message - Add to Buddy List

Edited: Aug 12, 2006, 02:43pm EDT

 
>> Re: java.lang.NoClassDefFoundError: in a Hello World program! Help!
Winking smilies aside, your code is fine. There must be something wrong with your Java SDK setup (or least that's my best guess).

I entered your code into TextPad and it compiled and ran fine. I also compiled it from the command line, also ran fine.

http://img53.imageshack.us/img53/738/javaczo9.png

And by the way, I'm using 1.5 (or 5.0) update 6 (not that it should matter).

Nathan Daniels Aug 12, 2006, 02:19pm EDT Reply - Quote - Report Abuse
Private Message - Add to Buddy List  
>> Re: java.lang.NoClassDefFoundError: in a Hello World program! Help!
darn. i am running the latest java as well.

--------
"The more we sweat in peace, the less we bleed in war."
-Patton
FordGT90Concept Aug 13, 2006, 09:34am EDT Reply - Quote - Report Abuse
Private Message - Add to Buddy List  
>> Re: java.lang.NoClassDefFoundError: in a Hello World program! Help!
package ConsoleApplication1;

/**
* Summary description for Program
*/
public class Hello
{
public static void main(String[] args)
{
System.out.println("Hello, World!");
System.out.println("It Worked!");
}
}

That worked fine for me in VS 2005 J#

________________________
If I remember what I forgot, I have not forgotten it.
Ex Member Aug 13, 2006, 12:25pm EDT Reply - Quote - Report Abuse
Private Message - Add to Buddy List  
>> Re: java.lang.NoClassDefFoundError: in a Hello World program! Help!
This looks like a classpath issue to me.

When compiling (javac), try using the fully qualified path of the file e.g.

If the file is C:\MyClasses\Hello.java then use this command: javac c:\MyClasses\Hello.java

This will create Hello.class in the same directory as Hello.java

To execute the program you would then need to use the following command:

java -classpath C:\MyClasses Hello

When using javac, the need to provide the full path of the Hello.java file can be avoided if you first switch to the directory where the file is using the CD command (javac looks in the current directory unless told otherwise).

When using the java command, the need to use the -classpath switch can be avoided by creating an environment variable called CLASSPATH and setting its value to the directory where your Hello.class file is located.

Hope this helps.

One other thing. The command line usage gets altered slightly if you organize your classes into packages. Post back if you get styuck further down the line with packages.

Nathan Daniels Aug 13, 2006, 02:26pm EDT Reply - Quote - Report Abuse
Private Message - Add to Buddy List  
>> Re: java.lang.NoClassDefFoundError: in a Hello World program! Help!
holy crap. that is too much work. Is there any way to compile and run a java porgram WITHOUT command prompt?

--------
"The more we sweat in peace, the less we bleed in war."
-Patton
Ex Member Aug 13, 2006, 02:58pm EDT Reply - Quote - Report Abuse
Private Message - Add to Buddy List  
>> Re: java.lang.NoClassDefFoundError: in a Hello World program! Help!
You could use an IDE. Personally, I would recommend Eclipse.It's free and it's good.

But its not that much work really. Creating the CLASSPATH variable takes like 1 minute and you only have to do it once. That sorts out the java.exe problem once and for all.

For javac.exe, typing the full path of a file takes slightly longer than just typing the filename. If that is too much then create a new text document and add the following text to it:

javac %1

Save it as compile.bat on your desktop, then every time you want to compile a .java file, simply drag and drop it onto this file and that will create the .class file for you.

FordGT90Concept Aug 13, 2006, 03:03pm EDT Reply - Quote - Report Abuse
Private Message - Add to Buddy List  
>> Re: java.lang.NoClassDefFoundError: in a Hello World program! Help!
http://msdn.microsoft.com/vstudio/express/visualj/

There's the free version of Visual J# 2005 if you want to take that route.

________________________
If I remember what I forgot, I have not forgotten it.
Ex Member Aug 13, 2006, 03:23pm EDT Reply - Quote - Report Abuse
Private Message - Add to Buddy List

Edited: Aug 13, 2006, 03:54pm EDT

 
>> Re: java.lang.NoClassDefFoundError: in a Hello World program! Help!
Visual J# is not Java, it is a .Net framework language that uses the same syntax as java. While VJ# does compile java source code the resulting binaries are not Java programs.

Programs compiled in VJ# are compiled into MIL which can only be run on the .Net Framework and cannot be run on a Java Virtual Machine. Any program that cannot be run on a JVM cannot reasonably be considered to be a Java program.

http://www.javaworld.com/javaworld/jw-11-2001/jw-1121-iw-jsharp.html

Sorry GT, I'm not having a go, just raising a (possibly moot) point :)

FordGT90Concept Aug 13, 2006, 04:47pm EDT Reply - Quote - Report Abuse
Private Message - Add to Buddy List

Edited: Aug 13, 2006, 04:50pm EDT

 
>> Re: java.lang.NoClassDefFoundError: in a Hello World program! Help!
.NET is the way programming is going these days. There's only one instance I've had to install JVM and lets just say it isn't worth installing JVM to run it. You'll have a much easier time convincing a user to download something that some drivers require and a majority of modern programs require than something that's used once a blue moon.

If JVM is the reason he's using it then sort out the Java compiler, otherwise it's a wise move to go with J#.

________________________
If I remember what I forgot, I have not forgotten it.
Ex Member Aug 13, 2006, 05:28pm EDT Reply - Quote - Report Abuse
Private Message - Add to Buddy List

Edited: Aug 15, 2006, 03:30pm EDT

 
>> Re: java.lang.NoClassDefFoundError: in a Hello World program! Help!
As I said, it is a moot point and yes, .Net is the way a lot of Windows programming is going. However, there are a vast number of commercial websites out there, and I mean vast, that are built using Java/MVC (e.g. Struts) frameworks running on Unix and Linux boxes and the number is growing unabated.

Now I don't want to get involved in a flame war, I just wanted to get my point across. But believe me, Java is huge. Not in the Windows world (I agree with you there), but in the Web Services world. I know, it's what I do for a living.

http://www.theinquirer.net/default.aspx?article=33103

I guess the question depends on what you are learning Java for, to write Windows apps? Why bother, .Net does that better. Or to build Web Apps where nothing comes close to it.

Again sorry if I got your back up, it was not an attack on you, just a clarification of what is and is not Java.



edited. Link added

Nathan Daniels Aug 13, 2006, 05:44pm EDT Reply - Quote - Report Abuse
Private Message - Add to Buddy List  
>> Re: java.lang.NoClassDefFoundError: in a Hello World program! Help!
I liked Dave Yarwood's idea better. I don't really like Visual J# or C# because it is such a resouce hog. I am working off of limited RAM.

--------
"The more we sweat in peace, the less we bleed in war."
-Patton
Aug 13, 2006, 05:56pm EDT Reply - Quote - Report Abuse
Private Message - Add to Buddy List  
>> Re: java.lang.NoClassDefFoundError: in a Hello World program! Help!
TextPad is a good program for Java. It's small, and has basic features like syntax highlighting and "Compile Java" and "Run Java" menu options. :_)

Ex Member Aug 13, 2006, 06:23pm EDT Reply - Quote - Report Abuse
Private Message - Add to Buddy List  
>> Re: java.lang.NoClassDefFoundError: in a Hello World program! Help!
Now that is an excellent suggestion. Wish I'd thought of that one myself ;).

I used a similar tool before I got into the big IDEs like IBM Websphere et al.

Also check out Sourceforge.net for other useful tools.

Nathan Daniels Aug 13, 2006, 06:36pm EDT Reply - Quote - Report Abuse
Private Message - Add to Buddy List

Edited: Aug 13, 2006, 06:38pm EDT

 
>> Re: java.lang.NoClassDefFoundError: in a Hello World program! Help!
Textpad didn't work. It got the same error. I am just going to re-install my Java SDK and see if that works. But that will take forever at 33kbs. I got my first from a CD.

--------
"The more we sweat in peace, the less we bleed in war."
-Patton
FordGT90Concept Aug 13, 2006, 06:54pm EDT Reply - Quote - Report Abuse
Private Message - Add to Buddy List  
>> Re: java.lang.NoClassDefFoundError: in a Hello World program! Help!
The IDE for Visual Studio is quite large, yes. devenv.exe with a project open takes up 100 MB by it self plus vchost and the like. It is quite the beast indeed but it can do a lot more than most IDEs can (eg memory editing, Just-In-Time debugging, etc.).

To run an application, it usually takes about 22 MB for the framework + the size of the application loaded.



Most websites are ASP, Perl, or PHP based. PHP is especially popular on Linux. JSP is very rare. You'll find that most corporate sites are ASP. e.g.:
http://www.creative.com
http://www.newegg.com
http://www.dell.com
http://www.hersheys.com

The rest were html extension which is either handled by something locally or masking.

The only site of about 10 I hit that actually used JSP was http://www.ea.com


By the way, there's a port for .NET Framework intended for use on Linux.

________________________
If I remember what I forgot, I have not forgotten it.
Aug 13, 2006, 07:13pm EDT Reply - Quote - Report Abuse
Private Message - Add to Buddy List

Edited: Aug 13, 2006, 07:13pm EDT

 
>> Re: java.lang.NoClassDefFoundError: in a Hello World program! Help!
I've never used ASP on a webpage, but I have used Perl and I continue to use PHP. :_) And I think you're right about Linux&PHP, I don't hear much about it unless it's being used on a Linux server.

XHTML+CSS+PHP = :_)

FordGT90Concept Aug 13, 2006, 07:36pm EDT Reply - Quote - Report Abuse
Private Message - Add to Buddy List  
>> Re: java.lang.NoClassDefFoundError: in a Hello World program! Help!
PHP works well on Windows so long as it isn't installed x64 Edition with IIS hosting. Apache + PHP works fine on pretty much all versions of Windows.

________________________
If I remember what I forgot, I have not forgotten it.
Aug 13, 2006, 07:41pm EDT Reply - Quote - Report Abuse
Private Message - Add to Buddy List  
>> Re: java.lang.NoClassDefFoundError: in a Hello World program! Help!
Really GT90?... why is that? I use PHP on Linux/Apache.

FordGT90Concept Aug 13, 2006, 07:46pm EDT Reply - Quote - Report Abuse
Private Message - Add to Buddy List  
>> Re: java.lang.NoClassDefFoundError: in a Hello World program! Help!
:s

I installed it locally to code and run 5 min execution blocks that hosts otherwise wouldn't allow. When PHP runs under IIS on x64 Edition, one of the worker processes of IIS keeps crashing. PHP works fine if you don't mind clicking OK every time the message comes up.

http://www.php.net/downloads.php

________________________
If I remember what I forgot, I have not forgotten it.
Nathan Daniels Aug 13, 2006, 07:57pm EDT Reply - Quote - Report Abuse
Private Message - Add to Buddy List  
>> Re: java.lang.NoClassDefFoundError: in a Hello World program! Help!
What the hell are you guys talking about?

--------
"The more we sweat in peace, the less we bleed in war."
-Patton

Write a Reply >>

Continue Reading on Page: 1, 2, Next >>

 

    
 
 

  Topic Tools 
 
RSS UpdatesRSS Updates
 

  Related Articles 
 
 

  Newsletter 
 
A weekly newsletter featuring an editorial and a roundup of the latest articles, news and other interesting topics.

Please enter your email address below and click Subscribe.