• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java Package  RSS feed

 
Rajarsi Ghosh
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • 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.
 
Nicola Guy
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are you typing to execute it?
 
Rajarsi Ghosh
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java Example
 
Nicola Guy
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • 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
 
Dan Grieve
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • 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
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanx Stan
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!