Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

CLASSPATH PROBLEM

 
vibhas karn
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello friends i am getting the following error message while compiling this simple program

class SimpleThread extends Thread
{
public void run()
{
System.out.println("Run new Thread ");

}
}

: the error it shows is as follows:-

SimpleThread.java:1: cannot access Thread
bad class file: .\Thread.java
file does not contain class Thread
Please remove or make sure it appears in the correct subdirectory of the classpa
th.
class SimpleThread extends Thread
^
####################
My CLASSPATH IS AS FOLLOWS:-

CLASSPATH
C:\Program Files\Java\jdk1.6.0_02\lib\tools.jar;.

OPERATING SYSTEM :-WINDOWSXP

Can anybody help me to remove this problem or what i suppose to do
 
Gamini Sirisena
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try putting "public" before the class keyword..
 
Gamini Sirisena
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry, that cant' be it..

First rename your class to something other than Thread, because there is already a Thread class in java.lang which is implicitly imported.

see if it works..
 
anu kuntala
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Vibhas,
May be you have created a class with name Thread in any other package.
In java we have Thread class in java.lang package. You should not mention your class name with already existing name. Check it.
Your classpath is correct. It is working in my System.

Regards,
Anu
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15495
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rename your source file Thread.java to SimpleThread.java, and make the SimpleThread class public:

public class SimpleThread { ...

Also, remove the tools.jar from your CLASSPATH. It doesn't belong there. In fact, you it's best not to set the CLASSPATH environment variable at all.
[ September 26, 2008: Message edited by: Jesper Young ]
 
vibhas karn
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys i think you all misinterpreted my question i am trying to extends the Thread class i change it to public class SimpleThread.java and even change the name to public class Simple.java and also change the classpath by removing tools.jar;. as suggested by my beloved friend.
But none works may be some problem which i still unable to understand.
But when i am importing java.lang.Thread its working fine and all Thread related programs which i tried and works. May be my program is not extending it which i think would have been done without writing explictly.
By the way its fine now if anybody finds any mistake in my opinion please kindly suggest me.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's the name of your file not the name of your class that's the problem. Because your file is called Thread.java, the compiler thinks it will find the Thread class in there.
 
snehasish barman
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, it's because you have named your file as "Thread.java" . if you use "import java.lang.* " and name the file as "Thread.java" then the compiler can see the package where the Thread class belongs... but if you don't mention the import statement explicitly here and name the file as "Thread.java" the compiler can't find the thread class so it doesn't matter if you create your own user-defined class .... just rename the file to something else and check.... it will definetly compile and execute...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic