This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

cannot resolve symbol - help  RSS feed

 
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
 
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.
 
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.
 
author
Sheriff
Posts: 23587
138
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
Sheriff
Posts: 23587
138
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
Sheriff
Posts: 23587
138
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
Sheriff
Posts: 23587
138
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
Sheriff
Posts: 23587
138
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
Sheriff
Posts: 23587
138
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
Sheriff
Posts: 23587
138
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
Boost this thread!