wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Package creation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Package creation" Watch "Package creation" New topic

Package creation

Neelima Paramsetty

Joined: Jun 17, 2003
Posts: 16
i created a directory called pack1.
in this i defiene a super class like this

After compiling this,i define a child class like this

when compiling child1.java .it is giving error like this"super class pack.parent1 of pack.child1
not found"
anybody help me to run this class.
thanks in advance,
[ edited to preserve formatting using the [code] and [/code] UBB tags -ds ]
[ July 15, 2003: Message edited by: Dirk Schreckmann ]
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
The compiler needs to be able to locate the base of your package structure through the CLASSPATH setting. So, the folder that holds the pack folder, needs to be somehow included in the CLASSPATH.
Try the following. (I'm working from my K:\java\temp folder.)
1. Create the pack folder - K:\java\temp\pack
2. Inside the K:\java\temp\pack folder, create parent1.java
3. From the command line, cd to K:\java\temp\pack and compile.
K:\java\temp\pack> javac parent1.java
It should compile successfully.
4. Inside the K:\java\temp\pack folder, create child1.java
5. From the command line, cd to K:\java\temp (NOT K:\java\temp\pack) and compile.
K:\java\temp> javac pack\child1.java
It should compile successfully, if your CLASSPATH is configured to include the current working directory (specified with a simple . - period). If it doesn't compile, then fix your CLASSPATH accordingly. Feel free to ask about how to do so.
6. You can now run the child1 program from the command line.
K:\java\temp>java pack.child1
And it should output the following.
Neelima Paramsetty
7. Any luck?
[ April 12, 2004: Message edited by: Dirk Schreckmann ]

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
James Clinton
Ranch Hand

Joined: Jun 23, 2003
Posts: 190
Using an IDE Tool will ease your classpath stress as you can setup/edit/customise them for individual projects.
Try using Forte by Sun Microsystems for example..its free.
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
Let me suggest that once you figure out the whole CLASSPATH thing, it's easy. I'd suggest not using an IDE at first. Using one will hide some of those details that a programmer might do well to be familiar with.
Neelima Paramsetty

Joined: Jun 17, 2003
Posts: 16
Dirk Schreckmann ,
Thanks for ur help.How to fix my class path?It is giving error when compiling child,java.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: Package creation
Similar Threads
Access to protected variable of class in one package from other package
calling parent class method using child class object
Constructing subclasses from superclass instance
Protected Constructors