my dog learned polymorphism*
The moose likes Beginning Java and the fly likes package problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "package problem" Watch "package problem" New topic
Author

package problem

Jit Gupta
Greenhorn

Joined: Jun 13, 2003
Posts: 26
I have created a package with the first line "package bookpack;" under which I have created a public class Book with three protected member: title, author and pubDate. The class has been compiled with "javac -d c:\ Book.java". After that compilation, I have verified that under c:\, bookpack directory has been created, and also Book.class file exists.
I have tried to create another package "package bookpackB;" under which I have attempted to create a subclass of "Book", writing "extends bookpack.Book". In the subclass I have tried to access the protected member of "Book" class. However, I am unable to compile that subclass.Errors appear that "unable to resolve symbol super, variables of "Book" class etc.
However, if I remove all package statements from both the superclass and subclass, all classes are compiled perfectly. I feel problem lies with the package creation.
Could some of you please help me in this regard?
Thanks in advance!
Richard Jensen
Ranch Hand

Joined: May 14, 2003
Posts: 67
If I understand correctly you are getting an error while compiling.
Is that the case?
Is the first package in your classpath when you compile the second class?
It might help to show the javac command for the second compile and the specific error message.


Richard
N 37 33 W 122 18
Jit Gupta
Greenhorn

Joined: Jun 13, 2003
Posts: 26
Thanks for your reply!
As I mentioned, the first package "bookpack"/class " Book" has been copiled.
Regarding second package("bookpackB")/class ("ExtBook"), I have used
"package bookpackB" and "class Book extends bookpack.book". I have tried to copile it with "javac -d c:\ ExtBook.java". My idea is that the copilation should create directory of "bookpackB" under c:\ and place "ExtBook.class" in that directory.
Am I wrong somewhere?
Richard Jensen
Ranch Hand

Joined: May 14, 2003
Posts: 67
As I said, I think that some code and the actual compile lines/error messages will help. This first example is what I think you are describing:

And I think your problem is your classpath when compiling ExtBook.

This compiled with no errors.
I had to tell javac where the class file from compiling Book.java went. Try that and see if it helps.
[ August 11, 2003: Message edited by: Richard Jensen ]
Jit Gupta
Greenhorn

Joined: Jun 13, 2003
Posts: 26
Thanks Richard, it has worked!
I have used javac command with classpath switch, as you mentioned. However, I have not used any import statement. What do you think? Do I have to set classpath variable in my batch file? Presently I am using "set classpath C:\j2sdk1.4\LIB ; . ;"
Anyway, I appreciate your help.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: package problem