• Post Reply Bookmark Topic Watch Topic
  • New Topic

A simple problem  RSS feed

 
Jacob Coddaire
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"
 
Atul Darne
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.
 
Campbell Ritchie
Marshal
Posts: 56562
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Atul Darne, please remember correct indentation and the code button.
 
Mathieu Fortin
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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!