• Post Reply Bookmark Topic Watch Topic
  • New Topic

static problems  RSS feed

 
Ben Hultin
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am getting a static reference context issue:



C:\Documents and Settings\ben\Desktop\park>javac BenHultinWeek5CatMouse.java
BenHultinWeek5CatMouse.java:26: cannot find symbol
symbol : method mate(java.util.ArrayList<Mouse>)
location: class BenHultinWeek5CatMouse
myProg.mate(mice);
^




Here is my Driver class:




Here is the driven class:




As you can see I have tried creating an object in the driver class to try and combat this, but still I get the problem. That idea may not even be remotely close to solving the issue since the all the code lays in the main method, this worked for me last time when I had class variable issues. But now it doesnt, any thoughts?
Thanks for the help
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


the problem is not about static

you are accessing the mate method by myProg which is an instance of BenHultinWeek5CatMouse class [it doesnt have mate method] . instead use Mouse class which has the particular method
 
Ben Hultin
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thats what I had originally, but I got the same result.



Maybe I am not calling the class correctly?
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ben Hultin wrote:Maybe I am not calling the class correctly?

Exactly


to make this work,
Make the mate method as static .
or
craete an Object of Mouse and Access mate


Hope Mouse and BenHultinWeek5CatMouse are in same Package.
 
Ben Hultin
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fixed it! It seems it was trying to access the method with an arraylist object. Java didnt like that. I created a separate object for calling in the non-static method and the error went away. Thanks for the help and the pointer.
 
Ben Hultin
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oops didnt know you posted, sorry about that
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ben Hultin wrote:Thanks for the help and the pointer.


You are welcome
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This code can't possible compile:mice is a list; lists don't have a getIsMale(int) method. There are other issues as well, but that's a starter. Once you've got a working program, I have additional suggestions.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!