Jump to content
  • Advertisement
Sign in to follow this  
LinkOfTime

[java] Running a program trouble...

This topic is 4912 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi I am just a beginner in Java programming and I have this book I am studing from. Now, when I try to run a program I get an error message: "Exception in thread "main" java.lang.NoClassDefFoundError: HelloDate/java" The code of the program is: import java.util.*; public class HelloDate { public static void main (String[] args) { System.out.println("Hello, it's: "); System.out.println(new Date()); } } Thanks in advance for the help :)

Share this post


Link to post
Share on other sites
Advertisement
Just a dumb question here, but what is your filename?
It should be HelloDate.java (case-sensitive on case-sensitive filesystems)
I've seen the error before and its something quite basic like that.

Then after you compile it with "javac HelloDate.java" (with extension) use "java HelloDate" to run it (no extension).

Good luck.

Share this post


Link to post
Share on other sites
Quote:
Original post by LinkOfTime
Hi
I am just a beginner in Java programming and I have this book I am studing from. Now, when I try to run a program I get an error message:
"Exception in thread "main" java.lang.NoClassDefFoundError: HelloDate/java"

You typed your command line, uh, command wrongly. Usually because you actually included .java in the class name (which you don't need to with the 'java' command). That or you're not pointing it at the right dir.

Share this post


Link to post
Share on other sites
Thanks for the help.
I have checked it and the name is written fine. :)
Anyway, it's still not working... :(
Can it have anything to do with the fact I have written "main" in small letters and not "Main" perhaps?
Thanks again for the help :)

Share this post


Link to post
Share on other sites
Java is case sensitive, I can't remember how it suppose to be, but try it.
But I think what the error is trying to say is that it can't find the class HelloDate declared in the file your trying to run.

I'm surprised its not giving you a line number for the error...

Share this post


Link to post
Share on other sites
Post your entire command line that you're typing and the exact output it gives. It'll be a problem there.

For checking your install is ok, type "java -version" and if you get 1.4 something or 1.5 something it's probably ok. Your program looks fine to me (and yes, main is with a lower case m - all methods in Java should begin with lower case letters).

Edit: Does it actually compile (via javac)? Post the output that you get from that. You do see a .class file being generated don't you?

Share this post


Link to post
Share on other sites
Well, I typed "java -version" and it gave me it's number (1.4.2_06).
Anyway, here are the commands I type:
"javac HelloDate.java" and for that command I don't receive any message at all, it just takes the computer about two seconds of processing to respond so I figured that it worked.
Then I type: "java HelloDate". For that message I get the error I have written in the original message...

Edit: Yes, a .class file is generated...

Share this post


Link to post
Share on other sites
I can't see any problems with the code per-say..

You are compiling it first with javac correct?
it should create a file called HelloDate.class
Then you run the class file with java HelloDate

So for example:
javac HelloDate.java
(HelloDate.class created)
java HelloDate

That should do it...
And I think you had main correct the first time, it is all lowercase.

And since you are compiling it, I'm assuming you installed the JDK (Java Development Kit) not just the JRE (Java Runtime Enviroment)?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!