| Author |
errorr in compling.. help
|
amit taneja
Ranch Hand
Joined: Mar 14, 2003
Posts: 806
|
|
hii in the following programe error is comming ..help me.. import java.util.Timer; import java.util.TimerTask; import java.awt.Toolkit; import java.util.Calendar; /** * Schedule a task that executes once every second. */ public class AnnoyingBeep { Toolkit toolkit; Timer timer; public AnnoyingBeep() { toolkit = Toolkit.getDefaultToolkit(); timer = new Timer(); timer.scheduleAtFixedRate(new RemindTask(), 5000, //initial delay 1*1000); //subsequent rate } class RemindTask extends TimerTask { int numWarningBeeps = 3; long int_time; public void run() { if(numWarningBeeps==3) int_time=getTimeInMillis(); if(getTimeInMillis()<=(int_time+1005)) if (numWarningBeeps > 0) { int_time+=1005; toolkit.beep(); System.out.println("Beep!"); numWarningBeeps--; } else { toolkit.beep(); System.out.println("Time's up!"); //timer.cancel(); //Not necessary because we call System.exit System.exit(0); //Stops the AWT thread (and everything else) } } } public static void main(String args[]) { System.out.println("About to schedule task."); new AnnoyingBeep(); System.out.println("Task scheduled."); } } ------------ error comming is .. D:\java_prac>javac AnnoyingBeep.java AnnoyingBeep.java:27: cannot resolve symbol symbol : method getTimeInMillis () location: class AnnoyingBeep.RemindTask int_time=getTimeInMillis(); ^ AnnoyingBeep.java:28: cannot resolve symbol symbol : method getTimeInMillis () location: class AnnoyingBeep.RemindTask if(getTimeInMillis()<=(int_time+1005)) ^ 2 errors D:\java_prac> why ? i didn't get ..i have included all the classes and it is not taking into consideration... tell me why this phenomenon happens generally..so i will take care into future..
|
Thanks and Regards,<br />Amit Taneja
|
 |
Saeed Amer
Ranch Hand
Joined: Jan 20, 2004
Posts: 135
|
|
Please qualify "getTimeInMillis()" with the class/object name and recompile! (qualify with class name if the method is static - object name otherwise) [ August 09, 2005: Message edited by: Saeed Amer ]
|
 |
Kj Reddy
Ranch Hand
Joined: Sep 20, 2003
Posts: 1697
|
|
Where did you defined getTimeInMillis()? The compiler clearly saying that it is not found getTimeInMillis(). Also suggestion for you at: if(numWarningBeeps==3) if you include {} it will be easily understandable to other users.
|
 |
John Wetherbie
Rancher
Joined: Apr 05, 2000
Posts: 1441
|
|
|
I think it is because it doesn't know what object/class getTimeInMillis is associated with. Get a calendar object and call its getTimeInMillis method.
|
The only reason for time is so that everything doesn't happen all at once.
- Buckaroo Banzai
|
 |
marc weber
Sheriff
Joined: Aug 31, 2004
Posts: 11343
|
|
You are trying to call the getTimeInMillis() method in the RemindTask class (which extends Timer). However, this method is in the Calendar class. You've imported Calendar so it's "visible" to the compiler, but you haven't actually used it. Within RemindTask, you need an instance of Calendar, so you can call myCalendar.getTimeInMillis(). (Note: If the method were static, then you would not need an instance, but could instead call it using the class name, Calendar.getTimeInMillis().)
|
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
|
 |
Kj Reddy
Ranch Hand
Joined: Sep 20, 2003
Posts: 1697
|
|
Try this: import java.util.Timer; import java.util.TimerTask; import java.awt.Toolkit; import java.util.Calendar; /** * Schedule a task that executes once every second. */ public class AnnoyingBeep { Toolkit toolkit; Timer timer; public AnnoyingBeep() { toolkit = Toolkit.getDefaultToolkit(); timer = new Timer(); timer.scheduleAtFixedRate(new RemindTask(), 5000, //initial delay 1*1000); //subsequent rate } class RemindTask extends TimerTask { int numWarningBeeps = 3; long int_time; public void run() { Calendar calendar = Calendar.getInstance(); // This is missing in your code if(numWarningBeeps==3) // didnt understnad this if loop int_time=calendar.getTimeInMillis(); if(calendar.getTimeInMillis()<=(int_time+1005)) // using calendar method if (numWarningBeeps > 0) { int_time+=1005; toolkit.beep(); System.out.println("Beep!"); numWarningBeeps--; } else { toolkit.beep(); System.out.println("Time's up!"); //timer.cancel(); //Not necessary because we call System.exit System.exit(0); //Stops the AWT thread (and everything else) } } } public static void main(String args[]) { System.out.println("About to schedule task."); new AnnoyingBeep(); System.out.println("Task scheduled."); } }
|
 |
 |
|
|
subject: errorr in compling.. help
|
|
|