Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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: 59108
180
  • 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
 
Shiny ad:
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!