• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

cant find variables problems

 
Ben Hultin
Ranch Hand
Posts: 135
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



.\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
Posts: 423
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 135
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Marshal
Pie
Posts: 20836
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Steven Hill
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Where is the mammal class?
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic