Home » Developer & Programmer » JDeveloper, Java & XML » Exception in thread "main" java.lang.NoClassDefFoundError:
Exception in thread "main" java.lang.NoClassDefFoundError: [message #231666] Wed, 18 April 2007 00:29 Go to next message
jadoo83
Messages: 26
Registered: October 2006
Location: Mumbai
Junior Member
Hi,

I am in learning phase of java and I am practicing the simple java programs.

I have created a package pack1 in which i have my father class.
Outside of the package i have son class & test class. These all three got compiled. Now when i am executing the test class then i am getting this error

Exception in thread "main" java.lang.NoClassDefFoundError: test (wrong name: pac
k1/test)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)

my father class code is as

package pack1;
class father
{
private int a;
int b;
protected int c;
public int d;
}

====================
my son class code is as

package pack1;
class son extends father
{
void show()
{
System.out.println("b= "+b);
System.out.println("c= "+c);
System.out.println("d= "+d);
}
}

====================

my test class code is as

package pack1;
class test
{
public static void main(String args[])
{
father f=new father();
System.out.println("b= "+f.b);
System.out.println("c= "+f.c);
System.out.println("d= "+f.d);
}
}

i have set classpath=.;D:\j2sdk1.4.1_01\bin

What should i do?

[Updated on: Wed, 18 April 2007 01:25]

Report message to a moderator

Re: Exception in thread "main" java.lang.NoClassDefFoundError: [message #231705 is a reply to message #231666] Wed, 18 April 2007 03:52 Go to previous messageGo to next message
Frank
Messages: 7901
Registered: March 2000
Senior Member
What do you mean "I have created a package pack1 in which i have my father class. Outside of the package i have son class & test class." ?
These three classes are all in the same package.
Re: Exception in thread "main" java.lang.NoClassDefFoundError: [message #231747 is a reply to message #231666] Wed, 18 April 2007 05:35 Go to previous messageGo to next message
tarmenel
Messages: 63
Registered: February 2007
Location: Israel
Member
As far as I can see, the problem may be that you need to have all three these classes in the same directory because they are part of the same package. I may be wrong here but try it and see if it works.
Re: Exception in thread "main" java.lang.NoClassDefFoundError: [message #231749 is a reply to message #231666] Wed, 18 April 2007 05:36 Go to previous message
tarmenel
Messages: 63
Registered: February 2007
Location: Israel
Member
You may also get a far quicker reply by posting on the forum at Java.Sun.com especially as this is not really specific to Oracle.
Previous Topic: OCI and Java
Next Topic: Java in Data Base
Goto Forum:
  


Current Time: Sun Nov 24 13:26:15 CST 2024