This week's book giveaway is in the JDBC forum.
We're giving away four copies of Make it so: Java DB Connections & Transactions and have Marcho Behler on-line!
See this thread for details.
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

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
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: 12
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: 3728

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: 12
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: 45415
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!