aspose file tools*
The moose likes Beginning Java and the fly likes cant find variables problems Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "cant find variables problems" Watch "cant find variables problems" New topic
Author

cant find variables problems

Ben Hultin
Ranch Hand

Joined: Aug 17, 2009
Posts: 135



.\Cat.java:26: cannot find symbol
symbol : variable selectedMouse
location: class java.util.ArrayList<Mouse>
mouseWeight = Mammal.getWeight(mice.selectedMouse);

^
.\Mouse.java:44: cannot find symbol
symbol : variable mouse1
location: class java.util.ArrayList<Mouse>
boolean mouse1Sex = Mammal.getIsMale(mice.mouse1);
^
.\Mouse.java:45: cannot find symbol
symbol : variable mouse2
location: class java.util.ArrayList<Mouse>
boolean mouse2Sex = Mammal.getIsMale(mice.mouse2);






I have declared these variables already inside the same method, so there is no issue with it being accessible or not.

My Mouse.java:




My Cat.java file:




I appreciate the help
Ireneusz Kordal
Ranch Hand

Joined: Jun 21, 2008
Posts: 423
Ben Hultin wrote:
symbol : variable selectedMouse
location: class java.util.ArrayList<Mouse>
mouseWeight = Mammal.getWeight(mice.selectedMouse);

mice is declared as ArrayList .... ArrayList dos not have field named 'selectedMouse'

Ben Hultin wrote:
symbol : variable mouse1
location: class java.util.ArrayList<Mouse>
boolean mouse1Sex = Mammal.getIsMale(mice.mouse1);

mice is declared as ArrayList .... ArrayList dos not have field named 'mouse1'

Ben Hultin wrote: ^
symbol : variable mouse2
location: class java.util.ArrayList<Mouse>
boolean mouse2Sex = Mammal.getIsMale(mice.mouse2);

mice is declared as ArrayList .... ArrayList dos not have field named 'mouse2'
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

And getIsMale shouldn't be a static method in Mammal, it should be an instance method of a Mammal.

Why do you construct a new Mammal in Mouse:8?

In any case--it still looks like you're just writing random code with the hope that it will compile and work. You really need to take a step back, write a *small* amount of code, make sure it compiles, make sure it does what you want, and move forward from there. Trying to fix *all* the problems at once is a sub-optimal solution (and there are a *lot* of problems here).

Make it easier on yourself and stop trying to do everything at once.
Ben Hultin
Ranch Hand

Joined: Aug 17, 2009
Posts: 135


mice is declared as ArrayList .... ArrayList dos not have field named 'mouse1'



so how wpuld I go about giving ArrayList a field named 'mouse1'. Are you meaning to say that it is trying to access an element inside the array called mouse1? How would define the arraylist to access an index number that is stored inside a varaible?
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18117
    
  39

Ben Hultin wrote:so how wpuld I go about giving ArrayList a field named 'mouse1'. Are you meaning to say that it is trying to access an element inside the array called mouse1? How would define the arraylist to access an index number that is stored inside a varaible?


Click on any of the many ArrayList links that the JavaRanch forum provided for you, in this topic. They go to the JavaDoc which describes the methods that does exactly what you want.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Steven Hill
Greenhorn

Joined: Apr 17, 2010
Posts: 1

Where is the mammal class?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: cant find variables problems
 
Similar Threads
cant find symbol problems
cant find API method problems
Dealing with ArrayList items in a static method
static problems
constructor problems