• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

error while using Timer ....

 
Ranch Hand
Posts: 817
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 817
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 547
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
cowbird
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 817
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Go back and take a look at your classpath.
 
amit taneja
Ranch Hand
Posts: 817
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
When evil is afoot and you don't have any arms you gotta be hip and do the legwork, but always kick some ... tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic