• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

thread not running on my comp...plz help

 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
/*This question from the herbert schildth book gives 10 error when compiled
Is there anything that is going wrong.*/

class CurrentThreadDemo extends Thread{
public static void main(String args[]) {
Thread t = Thread.currentThread();
System.out.println("Current thread: " + t);
// change the name of the thread
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 (InterruptedException e) {
System.out.println("Main thread interrupted");
}
}
}
/**
D:\MyJava\MyProg\Chap7@Threads@\CurrentThreadDemo.java:2: cannot resolve symbol
symbol : constructor Thread ()
location: class Thread
class CurrentThreadDemo extends Thread{
^
D:\MyJava\MyProg\Chap7@Threads@\CurrentThreadDemo.java:4: cannot resolve symbol
symbol : method currentThread ()
location: class Thread
Thread t = Thread.currentThread();
^
D:\MyJava\MyProg\Chap7@Threads@\CurrentThreadDemo.java:6: operator + cannot be applied to java.lang.String,Thread
System.out.println("Current thread: " + t);
^
D:\MyJava\MyProg\Chap7@Threads@\CurrentThreadDemo.java:9: cannot resolve symbol
symbol : method setName (java.lang.String)
location: class Thread
t.setName("My Thread");
^
D:\MyJava\MyProg\Chap7@Threads@\CurrentThreadDemo.java:10: operator + cannot be applied to java.lang.String,Thread
System.out.println("After name change: " + t);
^
D:\MyJava\MyProg\Chap7@Threads@\CurrentThreadDemo.java:15: cannot resolve symbol
symbol : method sleep (int)
location: class Thread
Thread.sleep(1000);
^
.\Thread.java:1: cannot resolve symbol
symbol : constructor Thread ()
location: class Thread
class A extends Thread {
^
.\Thread.java:3: incompatible types
found : A
required: java.lang.Object
synchronized (this) {
^
.\Thread.java:4: cannot resolve symbol
symbol : method wait ()
location: class A
try{wait();} catch (InterruptedException ie){}
^
.\Thread.java:10: cannot resolve symbol
symbol : method start ()
location: class A
a1.start();
^
10 errors
Tool completed with exit code 1
**/
 
Ranch Hand
Posts: 1090
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check your classpath. Run a simple program and check to see whether it compiles or not.
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Harvinder Singh,
I have checked your code. There is no problem with your code.
The problem appears to be with your classpath variable.
Do you have your current directory in your classpath?
The error reveals that the current directory is
D:\MyJava\MyProg\Chap7@Threads@\
If I assume you are not using packages. Please try to compile your java file i.e. CurrentThreadDemo.java using the following command lines.
set classpath=%classpath%;D:\MyJava\MyProg\Chap7@Threads@\
After that please run your java file.
I hope this will surely solve your problem.

Kind Regards
--------------------
Muzz
MSC Computing
"Sooner or later you're going to realize, just as I did, the difference between knowing the path... and walking the path."
NOTHING WORTH WHILE WILL EVER BE ACHIEVED WITHOUT DEEP THOUGHT AND HARDWORK - J.R.D TATA
 
reply
    Bookmark Topic Watch Topic
  • New Topic