Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / October 2006

Tip: Looking for answers? Try searching our database.

Newbie - Hello World

Thread view: 
Glenn Coyle - 24 Oct 2006 12:12 GMT
Hi

I know this is the most simple of things to do but for some reason it
does not work for me.

I have created the wonder Hello World App and it complies fine, but when
i run the class it does not work it comes up with the following error:

Exception in thread "main" java.lang.NoClassDefFoundError: HelloApp/Class

the code that i created is the following:

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

Thanks for the help, i really want to learn java, so if anyone can point
be to any good tutes tht would also be a great help.

G
Papastefanos Serafeim - 24 Oct 2006 12:18 GMT
> Hi
>
[quoted text clipped - 20 lines]
>
> G

Try running it using

java HelloApp

(instead of java.HelloApp.class)
Glenn Coyle - 24 Oct 2006 12:17 GMT
>>Hi
>>
[quoted text clipped - 26 lines]
>
> (instead of java.HelloApp.class)

Thats how i ran it and it comes up with that error, any idea?

could it be the way i have set up the java enviroment on my computer?
Gordon Beaton - 24 Oct 2006 12:33 GMT
> Exception in thread "main" java.lang.NoClassDefFoundError: HelloApp/Class

Papastefanos Serafeim wrote:
> Try running it using
> java HelloApp
>
> (instead of java.HelloApp.class)

> Thats how i ran it and it comes up with that error, any idea?

You are contradicting yourself. If that's really how you ran it, then
the error message you posted earlier is not the error message you
received. Post the real error message, or check the command line
again.

/gordon

Signature

[ don't email me support questions or followups ]
g o r d o n  +  n e w s  @  b a l d e r 1 3 . s e

Glenn Coyle - 24 Oct 2006 12:32 GMT
>>Exception in thread "main" java.lang.NoClassDefFoundError: HelloApp/Class
>
[quoted text clipped - 13 lines]
>
> /gordon

hi gordon

sorry take the /class off the error line

i ran it two ways

java HelloApp

and

java HelloApp.class

the only difference that i got in the error message was the /class

sorry does this make more sense?

I cant post a screen shot here can i to show what i am doing?
Mishagam - 24 Oct 2006 13:03 GMT
>>> Exception in thread "main" java.lang.NoClassDefFoundError:
>>> HelloApp/Class
[quoted text clipped - 3 lines]
>>> Try running it using
>>> java HelloApp

> sorry take the /class off the error line
>
[quoted text clipped - 11 lines]
>
> I cant post a screen shot here can i to show what i am doing?
May be you forgot to run java compiler?

javac HelloApp.java
Philip Reimer - 24 Oct 2006 13:08 GMT
Glenn Coyle schrieb:

>>> Exception in thread "main" java.lang.NoClassDefFoundError:
>>> HelloApp/Class
[quoted text clipped - 32 lines]
>
> I cant post a screen shot here can i to show what i am doing?

try "java -cp . HelloApp" in the directory containing HelloApp.class
Gordon Beaton - 24 Oct 2006 13:09 GMT
> i ran it two ways
>
[quoted text clipped - 5 lines]
>
> the only difference that i got in the error message was the /class

In that case try:

 java -cp . HelloApp

/gordon

Signature

[ don't email me support questions or followups ]
g o r d o n  +  n e w s  @  b a l d e r 1 3 . s e

Glenn Coyle - 24 Oct 2006 13:21 GMT
>>i ran it two ways
>>
[quoted text clipped - 11 lines]
>
> /gordon

winner

gold mate that works, can you let me know why it works this way and not
the other

sorry to be a pain
Gordon Beaton - 24 Oct 2006 13:25 GMT
> gold mate that works, can you let me know why it works this way and
> not the other

The argument to "java" isn't a filename, it's a classname. Java
searches the classpath for the class, and "-cp ." adds the current
directory to the classpath. You could also set CLASSPATH=. in your
environment.

/gordon

Signature

[ don't email me support questions or followups ]
g o r d o n  +  n e w s  @  b a l d e r 1 3 . s e

Tom Forsmo - 24 Oct 2006 14:35 GMT
>> gold mate that works, can you let me know why it works this way and
>> not the other
[quoted text clipped - 3 lines]
> directory to the classpath. You could also set CLASSPATH=. in your
> environment.

This means that for all code you write or use, java searches all the
paths in classpath to find the classes it is looking.
A CLASSPATH or -cp can look like this:

    CLASSPATH=.:/my/project/lib:/my/project/module1

In all these paths you can store any classfiles or jar files (Java class
ARchives) you need. This is basically a way to organise your code into
modules and allow access to external libraries.

tom
Jeff - 24 Oct 2006 16:53 GMT
> >> gold mate that works, can you let me know why it works this way and
> >> not the other
[quoted text clipped - 15 lines]
>
> tom

And don't forget that the package name acts as a sort of folder or
directory as well...
adwords@pulpjava.com - 28 Oct 2006 05:26 GMT
Getting a simply Java program running with the JDK is always a
challenge. I put together some free multimedia tutorials on my website
that show exactly what you need to do to get your simply Hello World
Java programs working with javac and the java utility.

www.scja.com

Cheers!

-Cameron McKenzie
Author of What is WebSphere?

For Free Java Certification Mock Exams: www.scja.com
Free Java and J2EE Multimedia Tutorials: www.mcnz.com
www.pulpjava.com www.technicalfacilitation.com

> Hi
>
[quoted text clipped - 20 lines]
>
> G


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.