aspose file tools*
The moose likes Java in General and the fly likes error while using Timer ....  Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "error while using Timer ....  " Watch "error while using Timer ....  " New topic
Author

error while using Timer ....

amit taneja
Ranch Hand

Joined: Mar 14, 2003
Posts: 806
hii

i have wrote the following code --

==================================================================

package org;
import java.util.Calendar;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;


/**
* @author user1
*
* To change this generated comment edit the template variable "typecomment":
* Window>Preferences>Java>Templates.
* To enable and disable the creation of type comments go to
* Window>Preferences>Java>Code Generation.
*/
class MainApplication {

public static void main(String[] args) {
Timer timer = new Timer();
Calendar date = Calendar.getInstance();
// date.set( Calendar.DAY_OF_WEEK,Calendar.SUNDAY);
date.set(Calendar.HOUR, 17);
date.set(Calendar.MINUTE, 12);
date.set(Calendar.SECOND, 0);
date.set(Calendar.MILLISECOND, 0);
// Schedule to run every Sunday in midnight
ReportGenerator obj = new ReportGenerator();
timer.schedule(obj,date.getTime(),1000);
}
}

class ReportGenerator extends TimerTask {

public void run() {
System.out.println("Generating report");
//TODO generate report
}

}

=======================================================================


IT GOT COMPILLED SUCCESSFULY

BUT FOLLOWING ERROR IS COMMING

================================


C:\amit\amit\org>java MainApplication
Exception in thread "main" java.lang.NoClassDefFoundError: MainApplication (wron
g name: org/MainApplication)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)

C:\amit\amit\org>


===================================


Y THIS ERROR IS COMMING ???

can anybody guide me please..... how to succesfully run the progrom..

later i will insert this code in servlet...




thanx and regards,
amit


Thanks and Regards, Amit Taneja
pascal betz
Ranch Hand

Joined: Jun 19, 2001
Posts: 547
this is a classpath problem. The JRE can not find your main class.
The fully qualified name of your MainApplication class is org.MainApplication. So you need to execute the command

C:\amit\amit\>java org.MainApplication
instead of
C:\amit\amit\org>java MainApplication

this should work.

there is also the -classpath (or -cp for short)flag you can pass to the JRE:
C:\projects\something>java -cp build org.something.App
(like this you specify that your org.something.App class is located in the build directory)

i hope this works for you now.

pascal
amit taneja
Ranch Hand

Joined: Mar 14, 2003
Posts: 806
thanx

ya pascal it runs


but nothing is happening in output....
it must print the result "Generating Report" after every one second from the time specified ..
but no out put is comming

the code is the same as above..i posted...
kindly try this....
and run this..... ( do me this favor )

i m developing the sheduler....

thanx and regards,
amit
pascal betz
Ranch Hand

Joined: Jun 19, 2001
Posts: 547
add this line


to see when the Task will be executed the first time...

just remove the date.setXXX() methods (or use a different Timer.schedule() method) and it will start right now.


pascal
Jef Cumps
cowbird
Ranch Hand

Joined: Nov 14, 2001
Posts: 53
Hi,

I tried your little prgram, and it works fine with me.. after I changed the hour set in your date member to an hour in the past. Try it first without all setters on your date, just pass the newInstance() to the timer. That will work. Then start experimenting with the setters on your date, watch out for AM and PM mistakes! (check the calendar-API)
amit taneja
Ranch Hand

Joined: Mar 14, 2003
Posts: 806
At home
this runtime error is comming

D:\java_prac>java org.MainApplication
Exception in thread "main" java.lang.NoClassDefFoundError: org/MainApplication


why this now :-(

pls help me to sort this out..

thanx for your earlier reply

regards,
amit
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Go back and take a look at your classpath.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
amit taneja
Ranch Hand

Joined: Mar 14, 2003
Posts: 806
oK THANX
every thing is working now...but now this i have to implement in servlet
but there is problem .....

i cannot create my servlet object to be passed in
sheduler obj= new sheduler();
// above i created the instance of servlet...in which i have writen
//sendRedirect() function... now how to call the servlet using
// timer.sheduler();
timer.shedule(obj.date.getTime(),1000);

Ok can any body tell me how to call a webpage from a class that is not servlet ...is it possible ?? actually i m developing a servlet which will be invoked at particular time and redirect page to some else page...

so
should i use threads in servlets ? can we use that ? but how..
i mean .... we should pass the object as an argument to Thread class..
can that object be servelt object ???

pls reply
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: error while using Timer ....
 
Similar Threads
Why oh why do I even Try??
Exception in thread "main" java.lang.NoClassDefFoundError
Problem executing jar
Assertion
Run class file error