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 / January 2005

Tip: Looking for answers? Try searching our database.

packages 101, java.lang.NoClassDefFoundError

Thread view: 
thufir - 15 Jan 2005 16:48 GMT
This works as expected, compiles and runs fine:
C:\java\sources\atreides\hello\> javac HelloWorldSwing.java -g
C:\java\classes\atreides\hello\

However, when I add "package atreides.hello;" to the first line of
HelloWorldSwing.java  I get the following error:

C:\java\classes\atreides\hello> java HelloWorldSwing
Exception in thread "main" java.lang.NoClassDefFoundError:
HelloWorldSwing
What am I doing wrong to get that, please?

thanks,

Thufir Hawat
klynn47@comcast.net - 15 Jan 2005 18:31 GMT
You can't add the package statement to the source code, unless you move
your class definition into a directory that matches the package
statement. So try creating a directory called atreides, and within that
a directory called hello, and place the source file and .class file
there. Then put the directory containing atreided in your CLASSPATH,
then either import atreides.hello.* or run java
atreides.hello.HelloWorldSwing
thufir - 15 Jan 2005 19:57 GMT
> You can't add the package statement to the source code, unless you move
> your class definition

Does class definition refer to whether a class is
public/private/other?

> into a directory that matches the package
> statement. So try creating a directory called atreides, and within that
> a directory called hello, and place the source file and .class file
> there. Then put the directory containing atreided in your CLASSPATH,
> then either import atreides.hello.* or run java
> atreides.hello.HelloWorldSwing
////////////////command line///////////////
C:>javac
-classpath C:\java\sources\atreides\hello\
HelloSwing.java

error: cannot read: HelloWorldSwing.java
///////////////command line//////////////////

My directory's are in order, I believe.  I'm reading
<http://java.sun.com/j2se/1.5.0/docs/tooldocs/windows/javac.html>,
but am a bit fuzzy as to the distinction between the
classpath, cp and sourcepath switches for javac.
Thanks,

Thufir Hawat
thufir - 15 Jan 2005 20:11 GMT
///////////////command line///////////////////////
C:\java\sources>javac atreides/hello/HelloSwing.java
C:\java\sources>java atreides.hello.HelloSwing
///////////////command line///////////////////////

The above works :)

How would I do it with the -classpath, or, more importantly, why?
thanks,

Thufir Hawat
klynn47@comcast.net - 16 Jan 2005 02:07 GMT
When I said import the package, that would be in the case where you
create an instance of the class HelloWorldSwing inside another class.
In that case, you would make sure that the directory containing
atriedes is in your CLASSPATH


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.