This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills and have John Sonmez on-line!
See this thread for details.
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


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "CLASSPATH PROBLEM" Watch "CLASSPATH PROBLEM" New topic
Author

CLASSPATH PROBLEM

vibhas karn
Greenhorn

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:-

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

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
Greenhorn

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.

Regards,
Anu
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14428
    
  23

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 ]

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

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 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

Joined: Aug 05, 2005
Posts: 3742
    
  16
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.


Joanne
snehasish barman
Ranch Hand

Joined: Aug 16, 2008
Posts: 30
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...


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: http://aspose.com/file-tools
 
subject: CLASSPATH PROBLEM