[java] Running a program trouble...
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 :)
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.
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.
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.
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 :)
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 :)
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...
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...
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?
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?
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...
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...
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)?
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)?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement