• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

errorr in compling.. help

 
amit taneja
Ranch Hand
Posts: 813
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..
 
Saeed Amer
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1704
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1449
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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().)
 
Kj Reddy
Ranch Hand
Posts: 1704
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.");
}
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic