aspose file tools*
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
Author

problem in thread program execution

chandan kuchipudi
Greenhorn

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 ....


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


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
Sheriff

Joined: Aug 22, 2010
Posts: 3611
    
  60

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
Greenhorn

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
Greenhorn

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

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39834
    
  28
Your new version compiles and runs without problem. You have obviously corrected the error.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: problem in thread program execution