| Author |
cannot resolve symbol - help
|
Dharmendran Govind
Greenhorn
Joined: Sep 08, 2008
Posts: 10
|
|
Dear friends, I am preparing for the SCP for java 2. I purchased this book by author Kathy Sierra. It is simply great... I am trying out some simple programs from the book. I had 2 classes in dir C:\JAVA\PROGRAMS First one is Parent.java package cert; public class Parent { protected int x = 9; } Second one is Child.java package other; import cert.Parent; class Child extends Parent { public void testIt() { System.out.println("x is " + x); } } The Parent class complies without issues. The Child class errors out saying "Cannot resolve symbol". I googled the message and checked for my classpath and all seem to be ok. Any help greatly appriciated. Regards Dgovi
|
 |
M Mehta
Ranch Hand
Joined: Aug 03, 2006
Posts: 92
|
|
|
You cannot access the protected members directly in the subclass class if the subclass is in different package.
|
 |
vidhya suvarna
Ranch Hand
Joined: Aug 28, 2008
Posts: 148
|
|
|
Protected variables of superclass can be accessed by subclass in a different package without any reference to the Subclass variable (through inheritance).
|
SCJP 1.4 - 88%<br />SCWCD 1.5 - Preparing
|
 |
Dharmendran Govind
Greenhorn
Joined: Sep 08, 2008
Posts: 10
|
|
Vidhya, Is'nt that what the code is doing? Trying to access variable X through inheritance, which is protected in the superclass that belong to a diff package.
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16811
|
|
It compiles fine for me. Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
Dharmendran Govind
Greenhorn
Joined: Sep 08, 2008
Posts: 10
|
|
wow, Hendry did you do any thing special. Can you please tell me how your classpath looks. I have installed J2SDK1.4.2_16. Regards Dgovi
|
 |
vidhya suvarna
Ranch Hand
Joined: Aug 28, 2008
Posts: 148
|
|
Dharmendran, yes your code is doing the same. But may be the problem is in the way your compiling in the required directory.
|
 |
Dharmendran Govind
Greenhorn
Joined: Sep 08, 2008
Posts: 10
|
|
Vidhya, I tried javac *.java and it complied fine. Thanks for your help though. Regards Dharmendran
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16811
|
|
Originally posted by Dharmendran Govind: I tried javac *.java and it complied fine. Thanks for your help though.
So, now everything works? What has changed? Henry
|
 |
vidhya suvarna
Ranch Hand
Joined: Aug 28, 2008
Posts: 148
|
|
hey if your current directory is C:\JAVA\PROGRAMS then compile your CHILD.class as C:\JAVA\PROGRAMS>javac other\Child.java and run it as C:\JAVA\PROGRAMS>java other\Child you need to specify the absolute path in both cases. There's another option where you need to set your classpath.
|
 |
Dharmendran Govind
Greenhorn
Joined: Sep 08, 2008
Posts: 10
|
|
Henry, Nothing changed. I googled and someone had tried compling javac *.java and it worked for that person. I also tried compling issuing javac *.java instead of javac Child.java and looks like javac *.java works. No idea why? Regards Dharmendran
|
 |
Dharmendran Govind
Greenhorn
Joined: Sep 08, 2008
Posts: 10
|
|
Vidhya Thanks for the tip. I tried compling javac other\Child.java. It is now giving me a diff kind of error "cannot read: other\Child.java". For some reason the complier is not seeing the file...
|
 |
vidhya suvarna
Ranch Hand
Joined: Aug 28, 2008
Posts: 148
|
|
I too tired the same way and it compiled fine. Henry, can you please help on this.
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16811
|
|
Dharmendran, since you are the one having problems, can you tell us your exact classpath, and the exact command line that you are using? Henry
|
 |
Dharmendran Govind
Greenhorn
Joined: Sep 08, 2008
Posts: 10
|
|
Henry My classpath is C:\oraclexe\app\oracle\product\10.2.0\server\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\PROGRA~1\IBM\CLIENT~1;C:\PROGRA~1\IBM\CLIENT~1\Shared;C:\PROGRA~1\IBM\CLIENT~1\Emulator;C:\Program Files\Common Files\Roxio Shared\DLLShared\;C:\Program Files\Common Files\Roxio Shared\DLLShared\;C:\Program Files\Common Files\Roxio Shared\9.0\DLLShared\;C:\Program Files\Common Files\Intuit\QBPOSSDKRuntime;C:\Program Files\QuickTime\QTSystem\;c:\Program Files\Microsoft SQL Server\90\Tools\binn;C:\J2SDK1.4.2_16\BIN;C:\J2SDK1.4.2_16\LIB;C:\J2SDK1.4.2_16\JRE;C:\JAVA\PROGRAMS
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16811
|
|
What's your class path? (Not your path variable, which is something different) And how are you compiling? Henry
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16811
|
|
Also, what is the full path location of the java files? Henry
|
 |
Dharmendran Govind
Greenhorn
Joined: Sep 08, 2008
Posts: 10
|
|
Henry Classpath is .;C:\J2SDK1.4.2_16\BIN;C:\J2SDK1.4.2_16\LIB;C:\J2SDK1.4.2_16\JRE;C:\JAVA\PROGRAMS The java files are in directory C:\JAVA\PROGRAMS Thanks for your help. Regards Dharmendran
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16811
|
|
The java files are in directory C:\JAVA\PROGRAMS
I am assuming that you mean ... Parent.java is in C:\JAVA\PROGRAMS\cert? And Child.java is in C:\JAVA\PROGRAMS\other? Henry [ September 08, 2008: Message edited by: Henry Wong ]
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16811
|
|
Classpath is .;C:\J2SDK1.4.2_16\BIN;C:\J2SDK1.4.2_16\LIB;C:\J2SDK1.4.2_16\JRE;C:\JAVA\PROGRAMS
You don't need most of the items in this classpath. You can get rid of everything except for C:\JAVA\PROGRAMS. And if your current directory is c:\JAVA\PROGRAMS, you actually don't need a classpath at all. Henry
|
 |
 |
|
|
subject: cannot resolve symbol - help
|
|
|