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 / GUI / April 2007

Tip: Looking for answers? Try searching our database.

Exception in thread "main" java.lang.NoClassDefFoundError: sampl

Thread view: 
xcrazy - 20 Apr 2007 04:58 GMT
Hi, I know this is a common error, but this occurs only in some of my
programs.
I run java on windows XP SP2, jdk1.5
My sampl.java file is like this:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

class swing_app {
       public static void main(String[] args) {
               JDesktopPane desktop = new JDesktopPane();
               desktop.add(desktop,BorderLayout.CENTER);
               JInternalFrame internalFrame = new
JInternalFrame("Internal
Frame",true,true,true,true);
               internalFrame.setBounds(50,50,200,100);
               desktop.add(internalFrame,new Integer(1));
       }

}

It compiles giving me a "sampl.class" file but when i type this
>java sampl

I get this error: - Exception in thread "main"
java.lang.NoClassDefFoundError: sampl

I don't get this error in a simple "Hello world" program.....
This is how i've set my paths:

Path=c:\j2sdkee1.3.1\bin;%SystemRoot%\system32;%SystemRoot%;
%SystemRoot
%\system32\WBEM;%SYSTEMROOT%\system32\WBEMC:
\PROGRA~1\COMMON~1\AUTODE~1;.;C:\Java\jdk1.5.0_09\bin;c:\Java
\jdk1.5.0_09\lib;

CLASSPATH= .;C:\Java\jdk1.5.0_09\lib;C:\Java\jdk1.5.0_09\bin;C:
\j2sdkee1.3.1\bin;

Please help!!
Knute Johnson - 20 Apr 2007 05:37 GMT
> Hi, I know this is a common error, but this occurs only in some of my
> programs.
[quoted text clipped - 37 lines]
>
> Please help!!

I don't know how you get it to compile if it is in a file named
sampl.java?  The file name and the class name must match.  Anyway your
program isn't going to do anything without a window or frame to hold
your components.  You should probably get rid of the CLASSPATH
environment variable too, it is almost never needed.

Signature

Knute Johnson
email s/nospam/knute/

Andrew Thompson - 20 Apr 2007 07:08 GMT
>> Hi, I know this is a common error, but this occurs only in some of my
>> programs.
..
>I don't know how you get it to compile if it is in a file named
>sampl.java?  

A file with a public class named sampl, can contain as many
'default' classes as the developer likes.  Since this class as
'default' access, I guess it can reside in a .java of any name.
So if the OP types..
java swing_app
..they will get to the..
Exception in thread "main" java.lang.IllegalArgumentException:
adding container's parent to itself

Signature

Andrew Thompson
http://www.athompson.info/andrew/

Thomas A. Russ - 20 Apr 2007 17:34 GMT
> > Hi, I know this is a common error, but this occurs only in some of my
> > programs.
> > I run java on windows XP SP2, jdk1.5
> > My sampl.java file is like this:
...
> > class swing_app {

> > It compiles giving me a "sampl.class" file but when i type this

> I don't know how you get it to compile if it is in a file named
> sampl.java?  The file name and the class name must match.

I think this is only true for public classes.  Non public classes can be
included in files with any name.  (Not that it's a good idea....)

Signature

Thomas A. Russ,  USC/Information Sciences Institute

Knute Johnson - 20 Apr 2007 22:22 GMT
>>> Hi, I know this is a common error, but this occurs only in some of my
>>> programs.
[quoted text clipped - 10 lines]
> I think this is only true for public classes.  Non public classes can be
> included in files with any name.  (Not that it's a good idea....)

You're right, if the class is declared public it must match the name of
the file.  If not public it will compile and it will produce class files
for every class.  You can even put main() methods in each of the classes
and run them.  I don't know what that does to package visibility.

Signature

Knute Johnson
email s/nospam/knute/



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.