Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

calling all objects!!

 
DANIEL GRESHAM
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to call a variable from another method that has a return statement, but for some reason i keep getting the same bug.
C:\Documents and Settings\Owner\Desktop\JavaPrograms\RobotRat1.java:288: cannot find symbol
symbol : variable spaces_to_move1
location: class RobotRat1
int spaces_to_move = spaces_to_move1.spaces_move();

and heres the code it goes with

public int spaces_move()
{
int spaces_to_move1 = 0;

try
{

spaces_to_move1 = Integer.parseInt(_textfield1.getText());
}
catch(NumberFormatException nfe)
{
System.out.println("Invalid integer value!");
System.out.println("spaces to move is being set to 1.");
spaces_to_move1 = 1;
_textfield1.setText("1");


}
return spaces_to_move1;
}

private void move()
{
int spaces_to_move = spaces_to_move1.spaces_move();

any help would be much appriciated, no rush on this im just experimenting with code to see how I can alter this program to make it more efficient.
thanks in advance
Danny
 
Steven Bell
Ranch Hand
Posts: 1071
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
spaces_to_move1 is an int and therfore does not have a method spaces_move()

On another note you might want to keep with standard naming conventions for your variables.

class/interface should be ClassName
method should be methodName()
variable shoud be variableName
static final variable shoud be VARIABLE_NAME

I doesn't effect the running of the program, but it effects the ability of others to read your code and you to read others code. Also when you post code please enclose it in code tags (there is a code button when you are posting). You can also go back and edit a post by clicking on the paper and pencil icon on your post.
 
Stephen Huey
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks like spaces_to_move1 is an int declared inside of the method spaces_move(), and you're trying to access this variable from inside the move() method. However, the move() method doesn't know anything about it. You could access the variable spaces_to_move1 if it were declared outside of any methods as a member variable of RobotRat1, but you'll need to decide if that's what you want to do. If you need to pass info to other methods, you can pass it as a parameter to the method.

Another problem is that even if it were declared outside of both methods so that they could both see it, you're trying to call spaces_to_move1.spaces_move(), but that doesn't make sense, because spaces_to_move1 is an int, which is a primitive type. Since it's not an Object, it can't have methods or member variables, so it doesn't have the method spaces_move().
 
DANIEL GRESHAM
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


tried the new idea, didnt work, heres the new error message
thanks anyway I'll just dink around with it and see whats going on
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic