This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes cannot resolve symbol - help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "cannot resolve symbol - help" Watch "cannot resolve symbol - help" New topic
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: 18509
    
  40

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: 18509
    
  40

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: 18509
    
  40

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: 18509
    
  40

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: 18509
    
  40

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: 18509
    
  40

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: 18509
    
  40

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
 
jQuery in Action, 2nd edition
 
subject: cannot resolve symbol - help
 
Similar Threads
Javac cannot find the parent class
problem on extending a class declared on the same package!!
How to create a package in Java?
default constructor must inside the Parent class. why?
about package