Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

cannot resolve symbol - help

 
Dharmendran Govind
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You cannot access the protected members directly in the subclass class if the subclass is in different package.
 
vidhya suvarna
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Protected variables of superclass can be accessed by subclass in a different package without any reference to the Subclass variable (through inheritance).
 
Dharmendran Govind
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 20894
76
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It compiles fine for me.

Henry
 
Dharmendran Govind
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vidhya,

I tried javac *.java and it complied fine.
Thanks for your help though.

Regards
Dharmendran
 
Henry Wong
author
Marshal
Pie
Posts: 20894
76
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I too tired the same way and it compiled fine.

Henry, can you please help on this.
 
Henry Wong
author
Marshal
Pie
Posts: 20894
76
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 20894
76
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's your class path? (Not your path variable, which is something different) And how are you compiling?

Henry
 
Henry Wong
author
Marshal
Pie
Posts: 20894
76
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, what is the full path location of the java files?

Henry
 
Dharmendran Govind
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 20894
76
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 20894
76
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic