Hi All,

I've just started using java and created a "HelloDate" program which works 100%. After that I created a "HelloWorld" program which didn't work because I had made a mistake in the code. I then rectified the mistake, deleted the class and then recompiled the "HelloWorld" program and it created a new class BUT when I run it I get the same error that I got when I initially created the program. The error I'm getting is "Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld/java

:confused:

Thanking you in advance
Randall

Are you by any means trying to run the java source file directly?
If you're commanding "java HelloWorld.java" you're actually trying to execute a class called 'java' in a package called 'HelloWorld'.
Compile the class using javac and then execute it using 'java HelloWorld' (while making sure your classpath is correctly set in either case).

Hi there,

Sorry for only replying now....

I don't quite understand, are you meant to be compiling a class??. I thought once you compile your java file it automatically creates a class for you?. Anyhow, I have tried compiling it and got the following error : "java c: invalid flag: HelloWorld.class"

Any other ideas?, or am I being really stupid and getting what you're trying to say? :confused:

Regards
Randall

It sounds like you already compiled the class. You should have the two files...

HelloWorld.java (this is where the Java code you wrote is)
HelloWorld.class (This should have been created when you ran 'javac HelloWorld.java')

To run HelloWorld you would just run the command 'java HelloWorld'.

Hope that helps...

-Fredric

Put java and c together.

Compile like this:

javac HelloDate.java

Run like this:

java HelloDate


If problems persist from there, then it's probably the environment variables.

Hi guys,

You lot didn't seem to have read my initial posting and replies.... Please can you read the initial posting and you willrealise that we've already eliminated the chance of it being an enviromental problem.....

PLEASE READ what I've already tried...

Thanking you in advcance
Randall

you're the one who's not paying attention. You might be a little less agressive when you're not getting an answer you understand, your behaviour is not making you any friends.

Your failure to get even the basic commandline syntax correct is your problem, not ours. People give you hints as to what to do, even spell it out for you, and still you don't get it.
Apparently you're not even trying, so why should we try to help you any further?

The error I'm getting is "Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld/java

This is a pretty generic error, and seems to be very common. It is telling you that whatever you typed after 'java' has no class definition (in this case it must have been 'HelloWorld.java' - going by the errror message you gave, which is wrong since the argument should only be 'HelloWorld'). This seems to be a problem with your understanding of how to properly compile/run a Java program, so please try what server_crash has already posted, and if you still have problems then post the error message that you are getting.

-Fredric

I'll bet money that one of us answered your question. Actually, all of us were hinting to the same thing.

I'm terribly sorry, I just read my posting and it does come accross very aggresive....

My apologies if I've offended anyone, it wasn't my intention.

However thank you for the replies, I'll take a look later when I get home.

Once again, sorry and thank you....

Randall

I'm terribly sorry, I just read my posting and it does come accross very aggresive....

My apologies if I've offended anyone, it wasn't my intention.

However thank you for the replies, I'll take a look later when I get home.

Once again, sorry and thank you....

Randall

No big deal...We all have our moments! ;)

Hi guys,

Thanks for the help...It's all good now..Working yay!! :cheesy:

Congrats. :)

-Fredric

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.