Main error in my HelloWorld output
I have this:
class HelloWorld
{
publicstaticvoid main(String args[])
{
System.out.println("Hello World!");
}
}
Now when I try and run in in my WindowsC:\Java\jdk1.5.0_06\bin
it doesnt work after it is compiled:
C:\Java\jdk1.5.0_06\bin>javac HelloWorld.java
C:\Java\jdk1.5.0_06\bin>java HelloWorld
Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld
Please advise what I need to set up correctly to get this to work?
[818 byte] By [
oaklandara] at [2007-11-26 20:48:48]

Do thisjava -cp . HelloWorldDon't miss the dot after -cp
> Please advise what I need to set up correctly to get this to work?java -classpath . HelloWorldResearch about what a classpath is all about please.
Assuming it compiled correctly and HelloWorld.java is in your current folder, you need to provide the classpath:java -cp . HelloWorldEdit: Well, at least we're all agreed on that.Message was edited by: DavidKN
1) Make sure the class is public. I can't remember if that's strictly necessary, but best just to do it.
2) Do java -cp . HelloWorld
Note the dot between -cp and HellowWorld. My guess is that you've installed quicktime, and, being the S.O.B. that it is, it set a (totally unnecssary) classpath environment variable, so the VM is looking for your class in a completely unrelated directory.
> > Please advise what I need to set up correctly to> get this to work?> > java -classpath . HelloWorld> > Research about what a classpath is all about please.Time for you to start whining.
> Time for you to start whining.What would I need to or want to whine about Questie?
> 1) Make sure the class is public. I can't remember if> that's strictly necessary, but best just to do it.It won't be necessary if we have only one class within a file or if none of the classes in a file contain the main method right?
> > Time for you to start whining.> > What would I need to or want to whine about Questie?Edited the post just to add Questie, eh!
> > > Time for you to start whining.
> >
> > What would I need to or want to whine about
> Questie?
>
> Edited the post just to add Questie, eh!
Oh boy, you sure caught me in the act. I don't know what to say about myself, I should be so ashamed.
What's your point Questie? <-- already put that there so I don't have to get caught editing it later
> > > > Time for you to start whining.
> > >
> > > What would I need to or want to whine about
> > Questie?
> >
> > Edited the post just to add Questie, eh!
>
> Oh boy, you sure caught me in the act. I don't know
> what to say about myself, I should be so ashamed.
Well you need to have something called as shame for that.
> What's your point Questie? <-- already put that there
> so I don't have to get caught editing it later
Nothing
> > What's your point Questie? <-- already put that
> there
> > so I don't have to get caught editing it later
>
> Nothing
Is that a coincidence related to the amount of active cells in your brain? One has to wonder.
(Edited: Changed "I" to "One has to" in the above. Questie needs to know each editing step I take, so this is for his benefit. I also have to justify why the change. The justification: Just because it sounds better. So there)
Well i must say that you edit your posts pretty well. Too good at it, aren't you? After all you were the one who pointed me to that editing option at the top tight of a post.
> > > What's your point Questie? <-- already put that
> > there
> > > so I don't have to get caught editing it later
> >
> > Nothing
>
> Is that a coincidence related to the amount of active
> cells in your brain?
Nah. My brain cells blew out years back. I am running on a backup.
>I wonder.
Can't expect more from you.
> Well i must say that you edit your posts pretty well.
> Too good at it, aren't you? After all you were the
> one who pointed me to that editing option at the top
> tight of a post.
Is post editing a "skill" which you think needs such recognition, or is this about the best thing you can come up with just to argue?
> > Well i must say that you edit your posts pretty
> well.
> > Too good at it, aren't you? After all you were the
> > one who pointed me to that editing option at the
> top
> > tight of a post.
>
> Is post editing a "skill" which you think needs such
> recognition, or is this about the best thing you can
> come up with just to argue?
Argue! Argue with whom? With you? If you are taking this is an arguement then i am just wasting my time. I was just pointing you to certain facts in this conversation which you undoubtedly have missed.
Thanks, it works with that command.
I thought I set the classpath correctly. Here is what I have:
set JAVA_HOME=C:\Java\jdk1.5.0_06
set PATH=%PATH%;%JAVA_HOME%\bin
Set CLASSPATH=%CLASSPATH%;C:\Program Files\Apache Software Foundation\Tomcat 5.5\common\lib\servlet-api.jar;C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\examples\WEB-INF\lib\struts.jar
I assume I need to add C:\Java\jdk1.5.0_06\bin to the classpath such as this command in Windows?
Set CLASSPATH=%CLASSPATH%;C:\Program Files\Apache Software Foundation\Tomcat 5.5\common\lib\servlet-api.jar;C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\examples\WEB-INF\lib\struts.jar;C:\Java\jdk1.5.0_06\bin
> I thought I set the classpath correctly. Here is
> what I have:
> set JAVA_HOME=C:\Java\jdk1.5.0_06
> set PATH=%PATH%;%JAVA_HOME%\bin
> Set CLASSPATH=%CLASSPATH%;C:\Program Files\Apache
> Software Foundation\Tomcat
> 5.5\common\lib\servlet-api.jar;C:\Program
> Files\Apache Software Foundation\Tomcat
> 5.5\webapps\examples\WEB-INF\lib\struts.jar
I don't think you need the apache and struts stuff on the classpath. I think tomcat picks it up from somewhere else. You'd have to look at tomcat's docs though.
> I assume I need to add C:\Java\jdk1.5.0_06\bin
> to the classpath such as this command in Windows?
> Set CLASSPATH=%CLASSPATH%;C:\Program Files\Apache
> Software Foundation\Tomcat
> 5.5\common\lib\servlet-api.jar;C:\Program
> Files\Apache Software Foundation\Tomcat
> 5.5\webapps\examples\WEB-INF\lib\struts.jar;C:\Java
> \jdk1.5.0_06\bin
No, absolutely not.
That bin directory should be on your PATH, *not* your CLASPATH.
jverda at 2007-7-21 18:04:15 >
