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

Problem compiling a Java Program

 
M Sharma
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not able to compile this simple program :-
public class PracThread extends Thread
{
public static void main(String args[])
{
System.out.println("IN the main method");
}
}
The error which it gives me is :-
PracThread.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 classpath.
public class PracThread extends Thread
^
1 error

My classpath is correctly set to :-
D:\j2sdk1.4.1_04\lib
I am compiling this program from c:\ and i am using Windows NT. When i give the set command on the command prompt it shows me the above classpath as a part of CLASSPATH variable.
But if i compile this program by giving
import java.lang.Thread; //as the first statement
as the first line then it compiles fine. I am unable to understand that why it is not able to get the Thread class. What settings should i change in order to compile it without any problems.
I have also included D:\j2sdk1.4.1_04\lib\tools.jar in my classpath. Please guide me to solve this problem.
TIA
Regards
Manish
 
Anurag Mishra
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Manish,
i don't think there is any problem with Programm.
there is some problem with path not classpath.
pls set in ur dos prompt path as
set path=D:\j2sdk1.4.1_04\bin;
it should work.
 
M Sharma
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My path is already set to D:\j2sdk1.4.1_04\bin; still its not working.
I will paste the whole classpath set in my system :
The CLASSPATH set in my system is :-
D:\j2sdk1.4.1_04\bin;D:\j2sdk1.4.1_04\lib;D:\j2sdk1.4.1_04\lib\tools.jar;C:\jsdk1.1\lib;c:\jsdk1.1\src;d:\.;
C:\javamail\javamail-1.2\activation.jar;C:\javamail\javamail-1.2\mail.jar;
D:\Tomcat\jakarta-tomcat-3.2.1\lib\classes12_01.zip;D:\Tomcat\jakarta-tomcat-3.2.1\lib\cocoon.jar;
D:\Tomcat\jakarta-tomcat-3.2.1\lib\jaxp.jar;D:\Tomcat\jakarta-tomcat-3.2.1\lib\xalan_1_0_1.jar;
D:\Tomcat\jakarta-tomcat-3.2.1\lib\xerces_1_0_3.jar;C:\j2sdkee1.3\lib\j2ee.jar;
D:\Tomcat\jakarta-tomcat-3.2.1\webapps\toml\WEB-INF\lib\toml_app.jar;d:\tomJars\utilJAR.jar;
D:\JExcelRead\jexcelapi\jxl.jar;D:\Tomcat\jakarta-tomcat-3.2.1\lib\PayScribe_ACH.jar;
D:\Tomcat\jakarta-tomcat-3.2.1\lib\PayScribe_Admin.jar;D:\Tomcat\jakarta-tomcat-3.2.1\lib\PayScribe_CombineImpl.jar;
D:\Tomcat\jakarta-tomcat-3.2.1\lib\PayScribe_Customer.jar;D:\Tomcat\jakarta-tomcat-3.2.1\lib\PayScribe_Merchant.jar;
D:\Tomcat\jakarta-tomcat-3.2.1\lib\PayScribe_Payment.jar;D:\Tomcat\jakarta-tomcat-3.2.1\lib\payscribe.jar;.;
The Path set in my system is :-
D:\j2sdk1.4.1_04\bin;D:\j2sdk1.4.1_04\lib;D:\Oracle\Ora81\bin;C:\Program Files\Oracle\jre\1.1.7\bin;%SystemRoot%\system32;%SystemRoot%;C:\Program Files\Common Files\Network Associates\VirusScan Engine\4.0.xx\;D:\Blazix;.;d:\;d:\tc;
Still i am facing the problem..
Please help !!!
[ August 14, 2003: Message edited by: Jim Yingst ]
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
remove all old JDK jars from your CLASSPATH. This can cause some
errors. But normally you don't have to add the java.lang package
jar to your classpath(I've never did that). So remove all old jar files.
BTW The path is not important to let it run. It only has to be set to be
able to call java, javac ... from each directory
 
M Sharma
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have removed C:\jsdk1.1\lib;c:\jsdk1.1\src; from the CLASSPATH. i think these were the only old jars present in the classpath.
Its still not working, and is giving me the same error.
Infact i am surprised as it was working fine till yesterday and i have not made any changes to the system apart from upgrading the sdk and jre to 1.4. But i don't think that the problem is coz of this, as the program runs fine if i add the import statement at the start of program or if i compile the java program with -classpath option and in the -classpath option i give the same path i.e. D:\j2sdk1.4.1_04\lib which is already present in the classpath.
I know that the PATH variable has nothing to do with the compilation, it only gives us access to utilities like java, javac etc.
I have also re-installed j2sdk and jre, but that too not worked..
Please help me to solve this problem.
TIA,
Manish
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi manish
first thing,
CLASSPATH u interpret seems to be incorrect. in CLASSPATH we have "jars" , "zip" files and .class files. So, if u didn't extracted tools.jar etc in the lib directory in ur java then just setting CLASSPATH to d:\j2sdk1.4.1_04\lib wont work. it should be d:\j2sdk1.4.1_04\lib\tools.jar. u see what i mean?
tho currently i'm unable to think more over ur problem.
regards
maulin
 
Roy Tock
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On my box, I successfully compiled and ran the program with this:
set PATH=C:\j2sdk1.4.1_03\bin
set CLASSPATH=
javac PracThread.java
java PracThread
Rather than trying to pare down your classpath & path, maybe try starting from scratch?
 
Roy Tock
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even more minimalist, this worked:
set PATH=
set CLASSPATH=
C:\j2sdk1.4.1_03\bin\javac PracThread.java
C:\j2sdk1.4.1_03\bin\java PracThread
 
Gayathri Prasad
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Yeah setting the class path for the the current session to the class made me execute my program.
Please try removing the old jars from the class files.
cheers,
Gaya3
 
M Sharma
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't have any sdk related old jars in my class path.
I tried to compile the program with -verbose option and it gave me the following output :
C:\>javac -verbose PracThread.java
[parsing started PracThread.java]
[parsing completed 251ms]
[loading .\Thread.java]
[parsing started .\Thread.java]
[parsing completed 10ms]
PracThread.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 classpath.
public class PracThread extends Thread
^
[total 1152ms]
1 error
From the above error it seems that it is trying to load the Thread class from the current directory instead of loading it from the classpath.
For your reference i am again pasting my classpath :
C:\>echo %classpath%
D:\j2sdk1.4.1_04\lib\tools.jar;d:\.;C:\javamail\javamail-1.2\activation.jar;C:\javamail\javamail-1.2\mail.jar;D:\Tomcat\jakarta-tomcat-3.2.1\lib\classes12_01.zip;D:\Tomcat\jakarta-tomcat-3.2.1\lib\cocoon.jar;D:\Tomcat\jakarta-tomcat-3.2.1\lib\jaxp.jar;D:\Tomcat\jakarta-tomcat-3.2.1\lib\xalan_1_0_1.jar;D:\Tomcat\jakarta-tomcat-3.2.1\lib\xerces_1_0_3.jar;C:\j2sdkee1.3\lib\j2ee.jar;D:\Tomcat\jakarta-tomcat-3.2.1\webapps\toml\WEB-INF\lib\toml_app.jar;d:\tomJars\utilJAR.jar;D:\JExcelRead\jexce lapi\jxl.jar;D:\Tomcat\jakarta-tomcat-3.2.1\lib\PayScribe_ACH.jar;D:\Tomcat\jakarta-tomcat-3.2.1\lib\PayScribe_Admin.jar;D:\Tomcat\jakarta-tomcat-3.2.1\lib\PayScribe_CombineImpl.jar;D:\Tomcat\jakarta-tomcat-3.2.1\lib\PayScribe_Customer.jar;D:\Tomcat\jakarta-tomcat-3.2.1\lib\PayScribe_Merchant.jar;D:\Tomcat\jakarta-tomcat-3.2.1\lib\PayScribe_Payment.jar;D:\Tomcat\jakarta-tomcat-3.2.1\lib\payscribe.jar;.;D:\j2sdk1.4.1_04\lib;D:\j2sdk1.4.1_04\bin;D:\j2sdk1.4.1_04\jre;
And my current path is set to :-
C:\>echo %path%
D:\j2sdk1.4.1_04\bin;D:\j2sdk1.4.1_04\lib;D:\Oracle\Ora81\bin;C:\Program Files\Oracle\jre\1.1.7\bin;C:\WINNT\system32;C:\WINNT;C:\Program Files\Common Files\Network Associates\VirusScan Engine\4.0.xx\;D:\Blazix;.;d:\;d:\tc;D:\j2sdk1.4.1_04\lib;D:\j2sdk1.4.1_04\jre;
I really appreciate for the time you guys have taken out in order to solve this problem.
The program compiles fine if i explicitly set the path for the current session, by giving the command
C:\>set classpath=D:\j2sdk1.4.1_04\lib
C:\>javac PracThread.java
C:\>java PracThread
Exception in thread "main" java.lang.NoClassDefFoundError: PracThread/java
C:\>set classpath=D:\j2sdk1.4.1_04\lib\tools.jar
C:\>javac PracThread.java
C:\>java PracThread
Exception in thread "main" java.lang.NoClassDefFoundError: PracThread
But it still doesn't run. Pls help!!!
[ August 16, 2003: Message edited by: Manish Sachdev ]
 
M Sharma
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry to trouble all of you. This program was not getting compiled because of my mistake. Initially before writing this program i had created a blank file with the name Thread.java in the current folder (c:\) and then i created program (PracThread.java). So when i was compiling this program the compiler was searching in the current package and was getting this blank Thread.java due to which my program was not getting compiled.
It was such a stupid mistake i have ever made in my life.
But anyways i learnt a lot from it and would never commit the same mistake ever again.
I appreciate the time and effort, which you guys took in order to help me out. :roll:
[ August 16, 2003: Message edited by: Manish Sachdev ]
 
Gayathri Prasad
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Good you traced it out.. Cheers !! No mistake is a stupid one.. Life is a process of continuous learning... See you are more learned than you were yesterday..All the best.
ATB,
Gaya3
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic