Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Overriding static methods with regards to TimerTask...

807605Jun 18 2007 — edited Jun 18 2007
Hello,

I'm attempting to call a method from another class (the method i'm calling is not static) in my own class which extends java.util.TimerTask...I've tried a few thing...but first, let me give you my code as it is currently
import java.util.*;

class myTimerTask extends java.util.TimerTask{
      public static void main(String[] args){
            run();
        }
        
        public static void run(){
         CSVFile record = new CSVFile();
          CSVFile.getRecord(index);
        }
}
In the code above, I get messages saying "run() in myTimerTask cannot override run() in java.util.timerTask; overriding method is static" and "non-static method 'getRecord' cannot be referenced from a static context"...In order to correct the first error I even tried the following to no avail:
public class myTimerTask{
                 public static void main(String [] args){
                          TimerTask task = new TimerTask(){
                                     public void run(){
                                                  CSVFile record = new CSVFile();
                                                  CSVFile.getRecord(index);
                                              }
                                       };
                           Timer myTimer = new Timer();
                           myTimer.schedule(task, 5000);
                   }
}
...would anyone be able to provide any insight as to how to get past static overriding methods, or a way of referencing a non static variable from a static context? Where I'm admittedly a novice, any other suggestions would be appreciated too.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 16 2007
Added on Jun 18 2007
6 comments
461 views