• 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

A simple problem  RSS feed

 
Ranch Hand
Posts: 36
Chrome Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm getting a coding problem that is quite simple to fix, I just can't figure out why it isn't working. I'm simplifying code to make it easier to read and to exclude the stuff that doesn't matter right now. I have two classes. One is GUIView, which has the method as follows:



The other class (Model) is trying to call the value of int size by using the following method.



The error is on size. "Size cannot be resolved to a variable"
 
Ranch Hand
Posts: 118
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
set the setter and getter methods for the first class;
if both he class are in same package you will be able to access the variable by Object of the class, usually by getSize() function written.

refer the class below.

Class One
{
private int size=0;
public void setBoardSize(int s)
{
this.size=s;
}

public int getSize()
{
return this.size;
}
 
Jacob Coddaire
Ranch Hand
Posts: 36
Chrome Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, that worked perfectly.
 
Marshal
Posts: 60062
188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Atul Darne, please remember correct indentation and the code button.
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And to the original poster, please do not name "getter" methods, that is, methods that only return the value of an attribute, with "set" prefix. It will make your code really confusing.

So instead of:


Do:


Mathieu
http://simpleadn.blogspot.com
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!