File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes A Baffling Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "A Baffling Question" Watch "A Baffling Question" New topic
Author

A Baffling Question

Gary Farms
Ranch Hand

Joined: Jun 24, 2000
Posts: 57
I have been plagued for several months with a classpath problem.
I must put a package statement at the top of my .java file otherwise I get a compile error. I've suffered with this problem for months now and tried everything. As an example, the following program compiles OK if I use the package statement at the top. However, if I comment it out, I get the following compile error:
incompatible types found: java.lang.String required on the line where my String array initialization takes place.
My classpath statement looks like this:
set classpath=.;%classpath%;c:\jdk1.3.0_02\lib;c:\java\;
My programs that generates the compile error w/o the package statement is:
//package com.gfarms.geometry;
public class Session6
{
public static void main(String[] args)
{
int[] a = new int[3];
a[0]=15;
a[1]=27;
a[2]=93;
double b[] = {2.4, 43.98, 200.597};
/* String c[] = new String[3];
c[0]="Gary";
c[1]="David";
c[2]="Farms"; */
String[] c = {"Gary", "David", "Farms"};
System.out.println("1st int = " + a[0]);
System.out.println("1st double = " + b[0]);
System.out.println("1st char = " + c[0]);
System.out.println("length of int array = " + a.length);
System.out.println("length of double array = " + b.length);
System.out.println("length of char array = " + c.length);

}
}
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Gary,
Try going to the DOS prompt and typing "set" and find out what your full classpath REALLY is. Also find out what your path is.

"JavaRanch, where the deer and the Certified play" - David O'Meara
Gary Farms
Ranch Hand

Joined: Jun 24, 2000
Posts: 57
Cindy. I ran "set" at the DOS prompt. Here's what I got. Can you tell why I always have this classpath problem requiring me to put a package statement at the top of my .java files to get a clean compile?
C:\>set
ALLUSERSPROFILE=C:\Documents and Settings\All Users
APPDATA=C:\Documents and Settings\farmsg\Application Data
CLASSPATH=c:\jdk1.3.0_02\lib;c:\java\;
CLASSPATH = .;c:\jdk1.3.0_02\lib;c:\java\;;c:\jdk1.3.0_02\lib;c:\java;
CommonProgramFiles=C:\Program Files\Common Files
COMPUTERNAME=GARY266
ComSpec=C:\WINNT\system32\cmd.exe
HOMEDRIVE=C:
HOMEPATH=\
LOGONSERVER=\\GARY266
NUMBER_OF_PROCESSORS=1
OS=Windows_NT
Os2LibPath=C:\WINNT\system32\os2\dll;
Path=c:\windows;c:\windows\command;c:\jdk1.3.0_02\bin;c:\java;
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
PROCESSOR_ARCHITECTURE=x86
PROCESSOR_IDENTIFIER=x86 Family 6 Model 3 Stepping 3, GenuineIntel
PROCESSOR_LEVEL=6
PROCESSOR_REVISION=0303
ProgramFiles=C:\Program Files
PROMPT=$P$G
SystemDrive=C:
SystemRoot=C:\WINNT
TEMP=C:\DOCUME~1\farmsg\LOCALS~1\Temp
TMP=C:\DOCUME~1\farmsg\LOCALS~1\Temp
USERDOMAIN=GARY266
USERNAME=farmsg
USERPROFILE=C:\Documents and Settings\farmsg
windir=C:\WINNT
C:\>

Originally posted by Cindy Glass:
Gary,
Try going to the DOS prompt and typing "set" and find out what your full classpath REALLY is. Also find out what your path is.

Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Try changing your classpath to c:\jdk1.3.0_02\jre\lib; Thats where the rt.jar lives usually.
Gary Farms
Ranch Hand

Joined: Jun 24, 2000
Posts: 57
Cindy:
I tried your latest suggestion, and modified my claspath to
c:\jdk1.3.0_02\jre\lib;
I still get the same result if I compile without a package statement. I ran the "set" command again (see below) after this new change to my classpath.
Why am I getting this? Why doesn't Java use the path statement instead of the classpath?

C:\java>set
ALLUSERSPROFILE=C:\Documents and Settings\All Users
APPDATA=C:\Documents and Settings\farmsg\Application Data
CLASSPATH=c:\jdk1.3.0_02\lib;c:\java\;
CLASSPATH = c:\jdk1.3.0_02\jre\lib;
CommonProgramFiles=C:\Program Files\Common Files
COMPUTERNAME=GARY266
ComSpec=C:\WINNT\system32\cmd.exe
HOMEDRIVE=C:
HOMEPATH=\
LOGONSERVER=\\GARY266
NUMBER_OF_PROCESSORS=1
OS=Windows_NT
Os2LibPath=C:\WINNT\system32\os2\dll;
Path=c:\windows;c:\windows\command;c:\jdk1.3.0_02\bin;c:\java;
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
PROCESSOR_ARCHITECTURE=x86
PROCESSOR_IDENTIFIER=x86 Family 6 Model 3 Stepping 3, GenuineIntel
PROCESSOR_LEVEL=6
PROCESSOR_REVISION=0303
ProgramFiles=C:\Program Files
PROMPT=$P$G
SystemDrive=C:
SystemRoot=C:\WINNT
TEMP=C:\DOCUME~1\farmsg\LOCALS~1\Temp
TMP=C:\DOCUME~1\farmsg\LOCALS~1\Temp
USERDOMAIN=GARY266
USERNAME=farmsg
USERPROFILE=C:\Documents and Settings\farmsg
windir=C:\WINNT
C:\java>
Originally posted by Cindy Glass:
Try changing your classpath to c:\jdk1.3.0_02\jre\lib; Thats where the rt.jar lives usually.

Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
I'm sorry - I only meant to change that PART of the classpath. It should be
CLASSPATH = .;c:\jdk1.3.0_02\jre\lib;c:\java\;
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
The path statement is for finding the executables like java.exe and javac.exe so it points at the bin files.
The classpath is to name the search path for finding class files to use. They are kept in the assorted .jar files and in whereever you are keeping YOUR stuff. The .jar files are equivalent to a sub-directory structure.
You could go LOOK to see where YOUR rt.jar and friends actually ARE.
[This message has been edited by Cindy Glass (edited August 01, 2001).]
Gary Farms
Ranch Hand

Joined: Jun 24, 2000
Posts: 57
I still have the same problem, even with the classpath you suggest. My latest classpath looks like this: classpath=.;c:\jdk1.3.0_02\jre\lib;c:\java\;
I also then did c:\@autoexec.bat before seeing if I still get a compile error without the package statement. I still do.
By the way, I searched for rt.jar, and it is in c:\jdk1.3.0)02\jre\lib exactly where my classpath defines it.
Any other ideas?


Originally posted by Cindy Glass:
The path statement is for finding the executables like java.exe and javac.exe so it points at the bin files.
The classpath is to name the search path for finding class files to use. They are kept in the assorted .jar files and in whereever you are keeping YOUR stuff. The .jar files are equivalent to a sub-directory structure.
You could go LOOK to see where YOUR rt.jar and friends actually ARE.
[This message has been edited by Cindy Glass (edited August 01, 2001).]

Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Is it JUST your String class that it spits up on? Perhaps you have an extra String class lying around causing trouble.
Also you might try re-typing that line of code. One person I worked with had a corrupt file and there was un-printable characters on the line confusing the compiler.
You don't have any extra JDKs lurking around do you - that sometimes causes problems.
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Please tell me that you are not using an IDE.
Gary Farms
Ranch Hand

Joined: Jun 24, 2000
Posts: 57
I have no other JDK's lurking around. Perhaps this additional info might help. I created a new file called Gary.java in my c:\java. I compile and run it there. It compiles OK with or without a package statement. But, it generates a run-time error of "Exception in thread "main" java.lang.NoSuchMethodError: main This run-time error occurs whether I have a package statement at the top or not. Here's c:\java\Gary.java
What's going on??? This is VERY strange!
//Gary.java
//package com.gfarms.geometry;
class Gary
{
public static void main(String[] args)
{
int i = 10;
System.out.println("value of i = " + i);
}
}

Originally posted by Cindy Glass:
Is it JUST your String class that it spits up on? Perhaps you have an extra String class lying around causing trouble.
Also you might try re-typing that line of code. One person I worked with had a corrupt file and there was un-printable characters on the line confusing the compiler.
You don't have any extra JDKs lurking around do you - that sometimes causes problems.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A Baffling Question