File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes core java creating package exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "core java creating package exception" Watch "core java creating package exception" New topic
Author

core java creating package exception

Vishal Hegde
Ranch Hand

Joined: Aug 01, 2009
Posts: 1056

package P;
class Example
{
public static void main(String args[])
{
System.out.println("creating package p");
}
}

i compiled this with

javac -d . Example.java

and made it run with

java Example


but it gave me an exception classNot found

why is it doing so??


http://www.lifesbizzare.blogspot.com || OCJP:81%
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42928
    
  68
Because a) the class is not named "Example", it is named "P.Example", and b) the class file is in the wrong location - it should be in a subdirectory called "P". You may want to read up on packages: http://java.sun.com/docs/books/tutorial/java/package/index.html
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
Try java P.Example

Have a look at the Java™ Tutorials and search this forum for "compiling package" where you should find at least three ways to compile classes with package names.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
Ulf, it is only Rob who is allowed to beat my by two minutes like that
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42928
    
  68
I promise to do worse in the future :-)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: core java creating package exception