• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

compilation error

 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI there,
I tried running this program but shows some compilation error of cannot find symbol . in following:
p1.num, p2.num and p3.num




please could someone help???
 
author & internet detective
Posts: 41878
909
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Raj,
In the future, please post the actual error message. It helps when looking what is wrong.

In your clase, the problem is that these lines expect there to be an instance variable named num in the Player class:


However, there is a local variable declared inside the method and no instance variables.

Also, a tip: In Java, there is a convention to begin variable names with a lower case letter. This convention makes it easier to determine what is a variable (vs a class) quickly.
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the below line of code



You are basically trying to access num which resides inside P1,P2,P3.

If your code is not able to access a member in class it means either that member is not defined in your class or the member has restrictive access.
See you Player class and try to find out is there "num" defined . You will understand the reason of this error.
 
Raj Gurung
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK. So because these are supposed to be declared as instance variables.
what about randomnum??? i didnot declare this separately but there is no error??
 
Jeanne Boyarsky
author & internet detective
Posts: 41878
909
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
randomNum is only used in the method it is declared. So a local variable is appropriate there.
 
Zulfiquiar Khan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Raj Gurung wrote:OK. So because these are supposed to be declared as instance variables.
what about randomnum??? i didnot declare this separately but there is no error??



Two reasons

1> Because randomNum is defined as local variable inside the method and it is accessed inside the same method.

2>Because you are not accessing randomNum using any reference variable. If you had it would have failed and given you the same error as you got for num.
 
reply
    Bookmark Topic Watch Topic
  • New Topic