File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes calling all objects!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "calling all objects!!" Watch "calling all objects!!" New topic

calling all objects!!


Joined: Feb 09, 2005
Posts: 21
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\ 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;


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;

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
Steven Bell
Ranch Hand

Joined: Dec 29, 2004
Posts: 1071
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

Joined: Jul 15, 2003
Posts: 618
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().

Joined: Feb 09, 2005
Posts: 21

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
I agree. Here's the link:
subject: calling all objects!!
It's not a secret anymore!