0

Hi!!!
am a cse student
How to create packages in java?
i used da "package" keyword and created a class in dat file . It gets compiled , but while execution i get dis error:
"Exception in thread "main" java.lang.NoClassDefFoundError:"
if i try to execute it by givin "java packagename.classname"
i encounter da same error

am new to java...pls help

3
Contributors
7
Replies
8
Views
8 Years
Discussion Span
Last Post by nittynotty
0

Hi!!!
am a cse student
How to create packages in java?
i used da "package" keyword and created a class in dat file . It gets compiled , but while execution i get dis error:
"Exception in thread "main" java.lang.NoClassDefFoundError:"
if i try to execute it by givin "java packagename.classname"
i encounter da same error

am new to java...pls help

Please post your code

0

If you have a class X in a package y, the JRE will look for X.class in a directory called y.
ie the class files must be in a directory structure that corresponds to your package structure.
So try creating a sub-dir with the same name as the package, put the class file in it, then start it from the parent directory using java packagename.classname

0

dis s ma code!!!!
package nitty;

class student
{
String name;
int reg;

public void accept(String a,int b )
{
name=a;
reg=b;
}

public void display()
{
System.out.println("Name: " +name);
System.out.println("reg: "+reg);
}

}

class studemo
{
public static void main(String args[])
{
student stud=new student();
stud.accept("nitty",3153);
stud.display();
}
}

0

pls tell me da command syntax i shud type in da prompt!!!!
or shud i access these classes from another class by importing this package????

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.