Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Stupid timertask question, i'm embarrassed even asking

Options
  • 29-11-2005 9:06pm
    #1
    Registered Users Posts: 2,320 ✭✭✭


    I keep getting "<identifier> expected" with this code at the timer.scheduleAtFixedRate(blah blah blah) method. What am i missing, i cant for the life of me see it. probably been looking at the code for too long
    import java.util.*;
    import java.io.*;
    
    public class TimerThread {
    
    	long auctionLength = 180000;
    	long auctionDelay = 10000;
    
    	Timer timer = new Timer();
    
    	TimerTask task = new TimerTask()
    	{
    
    		public void run()
    		{
    			System.out.println("blah");
    		} //end run
    
    	};//end timertask
    
    	timer.scheduleAtFixedRate(task, auctionDelay, auctionLength);
    
    }//end class
    

    its doing my nut in


Comments

  • Registered Users Posts: 1,068 ✭✭✭Magic Monkey


    Oops, erroneous advice removed. In any event, this may be of help.


  • Registered Users Posts: 7,498 ✭✭✭BrokenArrows


    Q_Ball wrote:
    I keep getting "<identifier> expected" with this code at the timer.scheduleAtFixedRate(blah blah blah) method. What am i missing, i cant for the life of me see it. probably been looking at the code for too long
    	TimerTask task = new TimerTask()
    	{
    
    		public void run()
    		{
    			System.out.println("blah");
    		} //end run
    
    	};  <=== Error Here No need for ;
    

    its doing my nut in


    hope that solves your problem


  • Closed Accounts Posts: 324 ✭✭madramor


    hope that solves your problem

    no, thats the correct way to do it.

    the problem is you are trying to execute code in a class that
    is not a declaration
    public class TimerThread {
        
        long auctionLength = 180000;
        long auctionDelay = 10000;
        Timer timer = new Timer();
        TimerTask task = new TimerTask(){
            public void run(){
                System.out.println("blah");
            }
        };
        // above all ok, below must be called in a method
        timer.scheduleAtFixedRate(task, auctionDelay, auctionLength);
        // also TimerThread has no constructor
    


  • Registered Users Posts: 7,498 ✭✭✭BrokenArrows


    oh ya sorry my bad didnt look at it right. Just had a quick look and saw it as a reg function.


  • Registered Users Posts: 19,396 ✭✭✭✭Karoma


    Disclaimer/Excuses: My head is ****ed. I haven't used Java in a while. I don't have the SDK installed, so I cannot test. Penguin.
    However..
    import java.util.*;
    import java.io.*;
    
    public class TimerThread
    { //hmmm..mebbe we should extends TimerTask ...*shrug* you try it and we'll see:)
    
            protected void startTask()
            {
                 
                 long auctionLength = 180000;
                 long auctionDelay = 10000;
    
                 TimerTask task = new TimerTask()
                 {
            
                      public void run()
                      {
                          try
                          {
                              System.out.println("blah");
                          }
                          catch(Exception e){}                         
                      } //end run
            
                 };//end timertask
                 
                  Timer timer = new Timer();
                  timer.scheduleAtFixedRate(task, auctionDelay, auctionLength);
            }
    }
    


  • Advertisement
Advertisement