File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes errorr in compling..  help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "errorr in compling..  help" Watch "errorr in compling..  help" New topic
Author

errorr in compling.. help

amit taneja
Ranch Hand

Joined: Mar 14, 2003
Posts: 810
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, Amit Taneja
Saeed Amer
Ranch Hand

Joined: Jan 20, 2004
Posts: 140
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: 1704
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: 1449
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: 1704
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.");
}
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: errorr in compling.. help