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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Stupid timertask question, i'm embarrassed even asking

  • 29-11-2005 8:06pm
    #1
    Registered Users, Registered Users 2 Posts: 2,325 ✭✭✭


    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, Registered Users 2 Posts: 1,068 ✭✭✭Magic Monkey


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


  • Registered Users, Registered Users 2 Posts: 7,501 ✭✭✭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, Registered Users 2 Posts: 7,501 ✭✭✭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, Registered Users 2 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