File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes CLASSPATH PROBLEM Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java


vibhas karn

Joined: Aug 11, 2008
Posts: 26
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:- cannot access Thread
bad class file: .\
file does not contain class Thread
Please remove or make sure it appears in the correct subdirectory of the classpa
class SimpleThread extends Thread

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


Can anybody help me to remove this problem or what i suppose to do
Gamini Sirisena
Ranch Hand

Joined: Aug 05, 2008
Posts: 378
Try putting "public" before the class keyword..
Gamini Sirisena
Ranch Hand

Joined: Aug 05, 2008
Posts: 378
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

Joined: Sep 25, 2008
Posts: 17
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.

Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15080

Rename your source file to, 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 ]

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
vibhas karn

Joined: Aug 11, 2008
Posts: 26
Hey guys i think you all misinterpreted my question i am trying to extends the Thread class i change it to public class and even change the name to public class 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

Joined: Aug 05, 2005
Posts: 3742
It's the name of your file not the name of your class that's the problem. Because your file is called, the compiler thinks it will find the Thread class in there.

snehasish barman
Ranch Hand

Joined: Aug 16, 2008
Posts: 30
Yes, it's because you have named your file as "" . if you use "import java.lang.* " and name the file as "" 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 "" 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...

Adobe Certified Expert Flex 4(ACE) (89%), SCJP 5.0 (97%), SCWCD 5.0 (100%), Adobe AIR/Java /J2EE/Spring/Apple iPhone & iPad Application Developer.
~~~ Arise, awake and stop not till the goal is achieved ~~~
I agree. Here's the link:
It's not a secret anymore!