• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

noclassdeffounderror

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..!!!..


 
Sheriff
Posts: 3064
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic