This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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!
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.
N 37 33 W 122 18
Joined: Jun 13, 2003
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?
Joined: May 14, 2003
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 ]
Joined: Jun 13, 2003
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.