Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem in thread program execution

 
chandan kuchipudi
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 3747
62
Chrome Netbeans IDE Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just change formatting & corrected typing errors. Does this what you want?

 
Campbell Ritchie
Sheriff
Pie
Posts: 47293
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your new version compiles and runs without problem. You have obviously corrected the error.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic