File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes problem in thread program execution Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "problem in thread program execution" Watch "problem in thread program execution" New topic

problem in thread program execution

chandan kuchipudi

Joined: Jun 27, 2012
Posts: 14
hi all.....i've got a problem while executing this thread based program.....actually my intension is to print 1 to 10 numbers with the gap of 1 second.....please look into that and help me ....

class Thread1 extends Thread
public void run()
for (int i=1; i<=10;i++ )
System.out.println("your time starts now="+i);
}catch (InterruptedException ie)
System.out.println("error in thread execution");
}//run ()
class ThreadDemo
public static void main(String[]args)
Thread1 t=new Thread1();

when i execute this prog , it is showing that error : line no.17

illegal static declaration in inner class Thread1.ThreadDemo

public static void main (String[]args)

modifier 'static ' is only allowed in constant variable declaration

please help ...
Martin Vajsar

Joined: Aug 22, 2010
Posts: 3732

As you can see, the code doesn't even compile; the problem has therefore nothing to do with threads. I'll move it to a better forum.

You can't declare anything as static in inner classes. Declare the main method directly in Thread1; you don't need the (inner) ThreadDemo class at all.
chandan kuchipudi

Joined: Jun 27, 2012
Posts: 14
thank you for help ....after writing the main method in Thread1 class , still it is showing an error like this ..

error line no:12 'catch' without 'try'

line no 6: try without catch ...

and Bear Bibeault......i've changed the name ....thank you for your concern...
anieruddha gaikwad

Joined: Nov 26, 2006
Posts: 13
Just change formatting & corrected typing errors. Does this what you want?

Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46320
Your new version compiles and runs without problem. You have obviously corrected the error.
I agree. Here's the link:
subject: problem in thread program execution
It's not a secret anymore!