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

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

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

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();
}
}

wats da mistake?

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????

Your main method needs to be in a public class.

thnk yo!! got output!!!!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.