Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

cant find methods

 
andrew cassato
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What error are you getting?
 
andrew cassato
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so you are saying it would need to be something like

?
 
buntha Choudhary
Ranch Hand
Posts: 136
Android Eclipse IDE Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 136
Android Eclipse IDE Windows XP
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks that did the trick, now to solving the rest!

thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic