[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Exception in thread "main" java.lang.NoClassDefFoundError - Java2sdk1.4.2_06

Posted on 2004-10-22
23
Medium Priority
?
87,637 Views
Last Modified: 2012-06-21
I've obviously a newbie to java, *ATTEMPTING* to teach myself, but I've run into a problem that's really held me up.

As you can see below, I'm attempting to run a java application called "helloworldapp".  helloworldapp.class (and .java) is located in c:\j2sdk1.4.2_06\bin\helloworldapp.
It compiles just fine but will not run.  I think there may be a classpath problem, but I've changed the path a ton of times and can't get it right.

_________________________________

C:\j2sdk1.4.2_06\bin\HelloWorldApp>javac helloworldapp.java

C:\j2sdk1.4.2_06\bin\HelloWorldApp>java helloworldapp
Exception in thread "main" java.lang.NoClassDefFoundError: helloworldapp (wrong
name: HelloWorldApp)
        at java.lang.ClassLoader.defineClass0(Native Method)
        at java.lang.ClassLoader.defineClass(Unknown Source)
        at java.security.SecureClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.access$100(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClassInternal(Unknown Source)

C:\j2sdk1.4.2_06\bin\HelloWorldApp>dir
 Volume in drive C has no label.
 Volume Serial Number is 549D-DF6C

 Directory of C:\j2sdk1.4.2_06\bin\HelloWorldApp

10/22/2004  03:46 PM    <DIR>          .
10/22/2004  03:46 PM    <DIR>          ..
10/22/2004  04:17 PM               432 HelloWorldApp.class
10/22/2004  03:59 PM               157 HelloWorldApp.java
               2 File(s)            589 bytes
               2 Dir(s)   3,418,599,424 bytes free
_____________________________________

Running WinXP SP2, and here's what I have for my environmental variables:

User variables:
CLASSPATH - .;C:\j2sdk1.4.2_06\bin
PATH - .;C:\j2sdk1.4.2_06\bin

System variables:
CLASSPATH - .;C:\j2sdk1.4.2_06\lib\tools.jar;C:\j2sdk1.4.2_06\jre\lib\rt.jar;C:\j2sdk1.4.2_06\jre\classes
JAVA_HOME - c:\j2sdk1.4.2_06
Path - %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\NMapWin\\bin;"C:\Program Files\Symantec\Norton Ghost 2003\";C:\j2sdk1.4.2_06\bin;JAVA_HOME;

I found many instances of this issue here and elsewhere and have tried most of their suggestions, and now I'm afraid I may have just completely messed it all up!

Please help!
0
Comment
Question by:tebacher
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
  • 3
  • +9
23 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 12385398
Try

java -classpath . helloworldapp
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 2000 total points
ID: 12385428
Java of course is case-sensitive, so the class name must be exactly as declared in the class file, and the same as the file name
0
 

Expert Comment

by:Ori_Kremer
ID: 12385438
As the exception suggests - you have a problem with names.
Try renaming the helloworldapp.java file to HelloWorldApp.java and running "java HelloWorldApp" .
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 8

Expert Comment

by:kiranhk
ID: 12385461
are you running your command from this path
C:\j2sdk1.4.2_06\bin\HelloWorldApp>java helloworldapp

check if your helloworldapp.java has got any package?? if it has any package you need to create the folders as in the package names in your java files and then place the class file in the last folder of your package. Then you can run ur app like

C:\j2sdk1.4.2_06\bin\HelloWorldApp>java com.helloworldapp.helloworldapp


the folder from where u run the command should also have the package starting  for your java class.
 so like in the above command if your package is com.helloworldapp then u should be having folders
C:\j2sdk1.4.2_06\bin\HelloWorldApp>
---------------->com------->helloworldapp

pl check out all these and test again.
hope this helps

0
 
LVL 9

Expert Comment

by:DrWarezz
ID: 12385600
See CEHJ's comment, if still no luck, try this:
just add this line, and press enter, before running (and preferably prior to compiling) your file:

set classpath=%classpath%;%cd%

Best of luck,
[r.D]
0
 
LVL 2

Expert Comment

by:ThummalaRaghuveer
ID: 12385702
Heres what your problem is...
 as suggested by CEHJ you are using wrong class name

You are using java helloworldapp

while the contents of the directory say its HelloWorldApp.class

so You should be using java HelloWorldApp

Here is a simple scenario that I tried without looking much into the problem and it even sounds the same....

Your file name is helloworldapp.java

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

It compiles and when U look at the contents of the directory U will get
helloworldapp.java
HelloWorldApp.class
Now try this in same file removing the above contents

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

It compiles as the public class name and file name are same but If You look at contents of directory You should get
helloworldapp.java
helloworldapp.class

but surprisigly I found HelloWorldApp.class instead of helloworldapp.class( I donno why this is happening)

but to execute it I need to give java helloworldapp

If I give java HelloWorldApp I get the following error

Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorldApp (wrong
name: helloworldapp)
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:605)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:12
4)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
        at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:290)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:279)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:236)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:303)

Which is exactly the error shown above......

So open HelloWorldApp.java

check the class name that contains main...

and then use that classname after java while trying to run.
0
 
LVL 92

Expert Comment

by:objects
ID: 12386023
run it using the following:

java HelloWorldApp

(your classpath is fine, and everything else appears fine)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12386042
That's already been said (several times)
0
 
LVL 92

Expert Comment

by:objects
ID: 12386070
Not directly (in fact only Ori did actually), and the above comments primarily talk about changing the classpath and filename which are all unnecessary.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12386097
However reliable the evidence of the classpath that's *actually being used is* (and that shouldn't be assumed to be 100% correct) all the information necessary to get this working has already been given
0
 
LVL 3

Expert Comment

by:oratim
ID: 12386110
Not to mention that it is not necessary to have the environment variable classpath set. I had a similar problem when I started coding in java, and fixed it by deleting the classpath env variable

0
 
LVL 92

Expert Comment

by:objects
ID: 12386120
So what exactly is your problem, with my clarifying what I believe to be the correct approach to run the command? As well as useful information, there is also a lot of erroneous information posted which could well confuse the asker. For eaxample, the suggestion that you posted will certainly *not* work.

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12386145
>>So what exactly is your problem, with my clarifying what I believe to be the correct approach

Simply that it's unnecessary. Your comments simply repeat what Ori Kremer said, which was the specific form of my more generic second comment
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 12387988
CEHJ & objects, don't fight! It's becoming a habit!

;JOOP!
0
 
LVL 9

Expert Comment

by:DrWarezz
ID: 12388009
lol - last time I had a disagreement with someone, I was threatened that I will loose my account for it! :o\

0
 
LVL 24

Expert Comment

by:sciuriware
ID: 12388016
By whom? Only moderators may tell you so.
;JOOP!
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 12388021
tebacher, next time you have such a problem, post your source;
it would have made this all easier and shorter.
;JOOP!
0
 
LVL 9

Expert Comment

by:DrWarezz
ID: 12388022
Yup -- it was moderators!
0
 
LVL 30

Expert Comment

by:GrandSchtroumpf
ID: 12390976
By the way, putting your java app in "C:\j2sdk1.4.2_06\bin" is not a good idea.
Using a directory of your own is much better (something like "C:\MyJavaProjects\HelloWorld").
0
 
LVL 5

Author Comment

by:tebacher
ID: 12399946
Wow, lots of help in this TA!  Thanks to everyone who has helped so far.

I *swear* I tried 'java HelloWorldApp' (with Caps as they should be) before I posted here!  But, after the weekend I booted up my PC and tried it with the caps, and it worked.   Just a case problem  :-)
Maybe I tried the Caps BEFORE I got the correct class path in and then just disregarded it from then on.

Anyway, thanks for the help!
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12400412
8-)
0
 
LVL 6

Expert Comment

by:SamsonChung
ID: 12563294
Aside from all the others' comments,

I suggest you to use an IDE for java..

some popular ones includes the paid ones such as borland, or JCreator Pro.

while the free ones such as Gel.

the IDE helps you a lot when it comes to memorization of different java packages and therefore allows you to easily learn Java.
0
 
LVL 1

Expert Comment

by:SchmidlinF
ID: 13323097
> Aside from all the others' comments,
> I suggest you to use an IDE for java..
> some popular ones includes the paid ones such as borland, or JCreator Pro.
> while the free ones such as Gel.

You must be kidding!?! Don't even think of looking further than the Eclipse IDE!
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question