This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

noclassdeffounderror

 
Anshul Singhal
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I ve made a folder java in my D drive. The folder Java contains a folder pckage1 and I ve written a following code under the name anshul.java


package pckage1;

import java.io.*;

class kkt
{
public void display()
{
System.out.println("this is kkt");
}

}


public class anshul extends kkt
{

public static void main()
{
System.out.println("anshul singhal");
anshul an = new anshul();
an.display();
}

}


this program compiles correctly using javac anshul.java but when i try to run it...(java anshul) it gives me a no class deffound error
my classpath is set to D:\java;

can someone please help..!!!..


 
Greg Charles
Sheriff
Posts: 2985
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you put a class into a package, you have to use that package name when referring to it. In your example, I think all that's wrong is you need to change the command to:

java pckage1.anshul

We also generally define main as:

public static void main(String [] args)

but I can't remember if the way you define it will prevent it from working or not.

One final point, on this bulletin board, we try to use code tags when posting code. It's really easy, and there are instructions on the site. I'm sure someone can provide a link.
 
Anshul Singhal
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I m sorry Charles..for nt putting my code in tags....

and about the soultion which you gave me I altered my main method by putting String args[] and replacing the first line java pckage1.anshul but still it doesn work out..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic