damienm
asked on
Compile problem
I have just started learning java and I copyed this example from a book (Java: the Compete Reference) but I cannot get it to compile properly.
class CurrentThreadDemo
{
public static void main(String args[])
{
Thread t = Thread.currentThread();
System.out.println("Curren t thread: " + t);
t.setName("My Thread");
System.out.println("After name change: " + t);
try
{
for (int n = 5; n > 0; n--)
{
System.out.println(n);
Thread.sleep(1000);
}
}
catch (InteruptedException e)
{
System.out.println("Main thread interrupted");
}
}
}
Line 16 I get error Interception thread must be caught in the throws clause of this method.
& Line 19 InteruptedException not found.
Thanks for your help
Damien
class CurrentThreadDemo
{
public static void main(String args[])
{
Thread t = Thread.currentThread();
System.out.println("Curren
t.setName("My Thread");
System.out.println("After name change: " + t);
try
{
for (int n = 5; n > 0; n--)
{
System.out.println(n);
Thread.sleep(1000);
}
}
catch (InteruptedException e)
{
System.out.println("Main thread interrupted");
}
}
}
Line 16 I get error Interception thread must be caught in the throws clause of this method.
& Line 19 InteruptedException not found.
Thanks for your help
Damien
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
thanx for appreciating my answer
which had performed a spellcheck for u
:):):):)
RJackman
which had performed a spellcheck for u
:):):):)
RJackman
ASKER
I figured out the answer when I was reading your answer even though your answer was not exactly the answer.
When reading your answer I noticed that I had spelt interrupted with only 1 r.
So I suppose you did give me the answer if not dirrectly.
Anyway Thanks
Damien