• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java Package

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I am trying to compile and execute the following piece of code.


package abc;

public class Example
{
Example()
{
System.out.println(" Example class constructor" );
}

public static void main (String[] args) {
Example newObj = new Example();
System.out.println("Exit main()");
}

}

When i am compiling the code it is getting compiled but when i am executing it i am getting the following error:
Exception in thread "main" java.lang.NoClassDefFoundError:

NB: I am executing it from the console and is not using any IDE.
 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What are you typing to execute it?
 
Rajarsi Ghosh
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
java Example
 
Nicola Guy
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well im relatively new to java too and had that error and it means it cant find the .class file your referring to so make sure the working directory is in the classpath as that is where the system will look for the .class file.

I think
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You asked the question a while ago but if you're still looking for an answer, try typing in cmd: java abc.Example

I'm not entirely sure but you may also need to place your Example.class in a folder called "abc". If you need to do this make sure you're trying to run it from the directory above the "abc" directory. So your cmd line should look like this:

C:\java>java abc.Example

Hope that helps
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Dan, welcome to the ranch!

See if this tutorial helps or confuses. There is a link in there to a good Sun tutorial on getting started, too.
 
Rajarsi Ghosh
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanx Stan
reply
    Bookmark Topic Watch Topic
  • New Topic