[Logo]
Forums Register Login
cant find variables problems
 




.\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
 

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'
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.
 



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?
 

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

Where is the mammal class?
His brain is the size of a cherry pit! About the size of this ad:
Thread Boost - a very different sort of advertising
https://coderanch.com/t/674455/Thread-Boost-feature


This thread has been viewed 1401 times.

All times above are in ranch (not your local) time.
The current ranch time is
Apr 24, 2018 19:11:51.