cannot resolve symbol problem
I've been looking around for a solution like hell for this chapter 6 problem. I finally found something in the p2p archives that worked though:
You can get around this by compiling all the classes in one shot:
javac com/wrox/library/*.java (on Unix. Try with \ instead of / on windows)
Cheers,
Dmitry
> Hello all,
>
> I need help in solving a problem:
>
> I'm trying to do inheritance using extends. I have book class as my
> superclass and two subclasses: ChildrenBook and TechnicalBook. I don't
> have any error when I compile the book class. However, I got compile
> error when I compile the two subclasses. This is the error message:
>
> ChildrenBook.java:3: cannot resolve symbol
> symbol : class Book
> location: class begjspCh07.ChildrenBook
> public class ChildrenBook extends Book
> ^
> 1 error
>
> I attach all my source code below:
> 1. Book.java
>
> package begjspCh07;
>
> public class Book
> {
> private String title;
>
> public String getTitle()
> {
> return title;
> }
>
> public void setTitle(String title)
> {
> this.title = title;
> }
>
> public Book()
> {
> }
>
> public Book(String title)
> {
> this.title = title;
> }
> }
>
> 2. ChildrenBook.java
>
> package begjspCh07;
>
> public class ChildrenBook extends Book
> {
> private int minimumAge;
>
> public int getMinimumAge()
> {
> return minimumAge;
> }
>
> public void setMinimumAge(int a)
> {
> minimumAge = a;
> }
>
> public ChildrenBook()
> {
> super();
> }
>
> public ChildrenBook(String title)
> {
> super(title);
> }
> }
>
> 3. TechnicalBook.java
>
> package begjspCh07;
>
> public class TechnicalBook extends Book
> {
> private String skillLevel;
>
> public int getSkillLevel()
> {
> return skillLevel;
> }
>
> public void setSkillLevel(String s)
> {
> skillLevel = s;
> }
>
> public TechnicalBook()
> {
> super();
> }
>
> public TechnicalBook(String title)
> {
> super(title);
> }
> }
>
> Thanks in advance,
> Lita Loe
This one finally worked for me. What I would like to know is *WHY* it works. I can't complie these files seperately, but they work fine when i do them all at once? I don't get it.
Also, I haven't tried this out yet, but I was looking at a response to another recent post from acmp2002 and it said to fix the problem try:
Hi
Try the following commands this will compile your code without error
For Book.java
javac -d "c:\Program Files\Apache Softwae Foundation\Tomcat 5.0\webapps\objects\WEB-INF\classes\booklibrary" booklibrary\Book.java
This command will create folder of your package name specified in your Book.java
For ChildrenBook.java
javac -d "c:\Program Files\Apache Softwae Foundation\Tomcat 5.0\webapps\objects\WEB-INF\classes\booklibrary" -classpath "c:\Program Files\Apache Softwae Foundation\Tomcat 5.0\webapps\objects\WEB-INF\classes\booklibrary" booklibrary\ChildrenBook.java
For TechnicalBook.java
javac -d "c:\Program Files\Apache Softwae Foundation\Tomcat 5.0\webapps\objects\WEB-INF\classes\booklibrary" -classpath "c:\Program Files\Apache Softwae Foundation\Tomcat 5.0\webapps\objects\WEB-INF\classes\booklibrary" booklibrary\TechnicalBook.java
Regards
Yashraj Chauhan
Java\J2EE Specialist
Wiley Support Team
does anyone know if that actually works? i suppose i should try it myself just to see.
Any explanation appreciated. Thanks,
JC
|