wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes cant find methods 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 methods" Watch "cant find methods" New topic
Author

cant find methods

andrew cassato
Ranch Hand

Joined: Nov 14, 2010
Posts: 37
I have been stuck on this for days! I am trying to call some methods once a button is pressed but i keep getting errors that the methods cant be found, I have tried a lot of different stuff but nothing is working. Here is the main class with the methods as well as the GUI class (where the problem of calling methods from the main class is happening.) and the last one is the Test class to run everything.


GUI


Test class


any help here would be SERIOUSLY appreciated. thanks in advance.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10519
    
    9

What error are you getting?


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
andrew cassato
Ranch Hand

Joined: Nov 14, 2010
Posts: 37
cannot find symbol - method setScores(double[])

i used to have Judging.setScores(scores) - which im pretty sure is more accurate - but i kept trying more and more random stuff out of frustration.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10519
    
    9

Your method setScores(double[] score) belongs to the Judging class. You are trying to invoke it from the JudgingGUI class.

Hint: Can you invoke a method without having a reference to the object which is the owner of the method?

Imagine a User class with a method getMailID() which returns the mail ID of that user.
Now imagine two users Andrew and Maneesh
Now imagine some class invoking the method getMailID() like the way you have coded.
Would the JVM know whose mail ID you are asking for? Andrew's or Maneesh's?
andrew cassato
Ranch Hand

Joined: Nov 14, 2010
Posts: 37
so you are saying it would need to be something like

?
buntha Choudhary
Ranch Hand

Joined: Jul 03, 2009
Posts: 136

andrew cassato wrote:so you are saying it would need to be something like

?


Then you will have to make your method static in the class. You can try the same by creating any instance of the Judging class and use that
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10519
    
    9

No. What you have there is a static method
What you need to do is obtain an instance of the Judging class and then invoke the setScores on it.

Judging judge=new Judging();
judge.setScore(scores);


Just remember, whenever you invoke setScores() you would want to invoke it on the same instance. So it the judge should be stored as a class variable in your JudgingGUI
andrew cassato
Ranch Hand

Joined: Nov 14, 2010
Posts: 37
Maneesh Godbole wrote:No. What you have there is a static method
What you need to do is obtain an instance of the Judging class and then invoke the setScores on it.

Judging judge=new Judging();
judge.setScore(scores);


Just remember, whenever you invoke setScores() you would want to invoke it on the same instance. So it the judge should be stored as a class variable in your JudgingGUI


this is obviously not that clear to me, I'm not 100% sure where to put
Judging judge=new Judging();
I tried a couple places but i get an error "cannot find symbol - variable judge" in the same place where i was getting errors before
buntha Choudhary
Ranch Hand

Joined: Jul 03, 2009
Posts: 136

andrew cassato wrote:
Maneesh Godbole wrote:No. What you have there is a static method
What you need to do is obtain an instance of the Judging class and then invoke the setScores on it.

Judging judge=new Judging();
judge.setScore(scores);


Just remember, whenever you invoke setScores() you would want to invoke it on the same instance. So it the judge should be stored as a class variable in your JudgingGUI


this is obviously not that clear to me, I'm not 100% sure where to put
Judging judge=new Judging();
I tried a couple places but i get an error "cannot find symbol - variable judge" in the same place where i was getting errors before


Sample -

andrew cassato
Ranch Hand

Joined: Nov 14, 2010
Posts: 37
thanks that did the trick, now to solving the rest!

thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: cant find methods