Solved

Compile problem

Posted on 2000-03-21
3
344 Views
Last Modified: 2008-03-17
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("Current 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
0
Comment
Question by:damienm
  • 2
3 Comments
 
LVL 3

Accepted Solution

by:
rjackman earned 30 total points
ID: 2640023
hi damienm

check ur code
>>catch (InteruptedException e)
                     {
                       System.out.println("Main thread interrupted");
                     }

>>InteruptedException e
it should be
catch (InterruptedException e)
                     {
                       e.printStackTrace();
                     }

always use printStackTrace() method to get the stack trace where u have gone wrong
now it will work fine
RJackman
0
 
LVL 2

Author Comment

by:damienm
ID: 2640521
Hi Rjackman

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
0
 
LVL 3

Expert Comment

by:rjackman
ID: 2643333
thanx for appreciating my answer
which had performed a spellcheck for u
:):):):)
RJackman
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now