compile trouble

I recently wiped my drive and upgraded to winxp and now cannot get my java to compile. Installed my os to my D drive and set both path and class path. I have read the troubleshooting thread and i can do this just fine:

====

D:\>cd d:\development

D:\development>javac HelloWorld.java

D:\development>java HelloWorld

Hello Java World! Here I come.

D:\development>

====

However, in trying the sun tutorial here:

http://java.sun.com/developer/onlineTraining/new2java/divelog/

I am encountering problems. This exact project compiled fine before but now i keep getting 'symbol not found' errors. Check it out:

====

D:\Documents and Settings\Jaithe>cd d:\divelog

D:\divelog>javac DiveLog.java

DiveLog.java:53: cannot find symbol

symbol : class Welcome

location: class divelog.DiveLog

new Welcome(),

^

DiveLog.java:58: cannot find symbol

symbol : class Diver

location: class divelog.DiveLog

new Diver(),

^

DiveLog.java:63: cannot find symbol

symbol : class Dives

location: class divelog.DiveLog

new Dives(),

^

DiveLog.java:68: cannot find symbol

symbol : class Statistics

location: class divelog.DiveLog

new Statistics(),

^

DiveLog.java:73: cannot find symbol

symbol : class WebSite

location: class divelog.DiveLog

new WebSite(),

^

DiveLog.java:78: cannot find symbol

symbol : class Resources

location: class divelog.DiveLog

new Resources(),

^

6 errors

D:\divelog>

====

I know what you're thinking. Are the files there? Yes they are:

====

D:\divelog>dir

Volume in drive D has no label.

Volume Serial Number is FC6B-56F6

Directory of D:\divelog

04/26/2006 06:36 PM<DIR> .

04/26/2006 06:36 PM<DIR> ..

04/26/2006 06:35 PM 2,545 CenterPanel.class

03/01/2006 01:37 PM 1,933 CenterPanel.java

03/01/2006 04:20 PM 1,953 CenterPanel_modified.java

04/26/2006 06:33 PM8 compile.bat

04/26/2006 06:23 PM82 Copy of compile.bat

03/01/2006 12:56 PM189 divedetails.txt

03/01/2006 09:49 PM 1,715 DiveHandler.java

04/26/2006 07:40 PM511 DiveLog$1.class

04/26/2006 07:40 PM555 DiveLog$2.class

04/26/2006 07:40 PM 2,458 DiveLog.class

03/01/2006 10:07 AM 2,662 DiveLog.java

04/26/2006 06:33 PM182 Diver$1.class

04/26/2006 06:33 PM902 Diver$CheckBoxHandler.class

04/26/2006 06:33 PM 5,786 Diver.class

03/01/2006 10:14 AM 9,753 Diver.java

04/26/2006 06:34 PM 1,738 DiveRecord.class

03/01/2006 04:37 PM 1,583 DiveRecord.java

03/01/2006 04:22 PM847 Dives.java

04/26/2006 05:50 PM<DIR> images

04/26/2006 06:36 PM 2,246 NorthPanel.class

03/01/2006 01:01 PM 1,871 NorthPanel.java

04/26/2006 05:55 PM130 README.TXT

04/26/2006 06:35 PM202 Resources.class

02/28/2006 01:01 AM297 Resources.java

04/26/2006 05:29 PM35 run.bat

03/01/2006 01:40 PM72 saved_comment.txt

04/26/2006 06:35 PM204 Statistics.class

02/28/2006 01:02 AM298 Statistics.java

03/01/2006 06:00 PM 6,247 UIWestPanel.java

04/26/2006 06:35 PM198 WebSite.class

02/28/2006 01:02 AM295 WebSite.java

04/26/2006 06:34 PM 1,910 Welcome.class

02/28/2006 03:08 PM 1,612 Welcome.java

04/26/2006 06:34 PM202 WestPanel.class

03/01/2006 10:52 AM137 WestPanel.java

34 File(s) 51,358 bytes

3 Dir(s) 32,584,663,040 bytes free

D:\divelog>

====

I have also tried with classpath:

====

D:\divelog>javac -cp . DiveLog.java

DiveLog.java:53: cannot find symbol

symbol : class Welcome

location: class divelog.DiveLog

new Welcome(),

^

DiveLog.java:58: cannot find symbol

symbol : class Diver

location: class divelog.DiveLog

new Diver(),

^

DiveLog.java:63: cannot find symbol

symbol : class Dives

location: class divelog.DiveLog

new Dives(),

^

DiveLog.java:68: cannot find symbol

symbol : class Statistics

location: class divelog.DiveLog

new Statistics(),

^

DiveLog.java:73: cannot find symbol

symbol : class WebSite

location: class divelog.DiveLog

new WebSite(),

^

DiveLog.java:78: cannot find symbol

symbol : class Resources

location: class divelog.DiveLog

new Resources(),

^

6 errors

D:\divelog>

====

I have tried other classpath values also like d:\ and "D:\Program Files\Java\jdk1.5.0_06" but that only results in the compiler not finding classes like Vector and Jbutton.

So what's the deal? I am very new to Java so it could be something else, but like i said, these files compiled fine before i wiped my drive.

FYI, here are my environment vars:

====

D:\divelog>set

ALLUSERSPROFILE=D:\Documents and Settings\All Users

APPDATA=D:\Documents and Settings\Jaithe\Application Data

CLASSPATH=.

CLIENTNAME=Console

CommonProgramFiles=D:\Program Files\Common Files

COMPUTERNAME=TABERNACLE

ComSpec=D:\WINDOWS\system32\cmd.exe

FP_NO_HOST_CHECK=NO

HOMEDRIVE=D:

HOMEPATH=\Documents and Settings\Jaithe

JAVA_HOME=D:\Program Files\Java\jdk1.5.0_06

LOGONSERVER=\\TABERNACLE

NUMBER_OF_PROCESSORS=1

OS=Windows_NT

Path=D:\WINDOWS\system32;D:\WINDOWS;D:\WINDOWS\System32\Wbem;D:\Program Files\Ja

va\jdk1.5.0_06\bin;D:\Program Files\Java\jdk1.5.0_06\lib;

PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH

PROCESSOR_ARCHITECTURE=x86

PROCESSOR_IDENTIFIER=x86 Family 15 Model 1 Stepping 2, GenuineIntel

PROCESSOR_LEVEL=15

PROCESSOR_REVISION=0102

ProgramFiles=D:\Program Files

PROMPT=$P$G

SESSIONNAME=Console

SystemDrive=D:

SystemRoot=D:\WINDOWS

TEMP=D:\DOCUME~1\Jaithe\LOCALS~1\Temp

TMP=D:\DOCUME~1\Jaithe\LOCALS~1\Temp

USERDOMAIN=TABERNACLE

USERNAME=Jaithe

USERPROFILE=D:\Documents and Settings\Jaithe

windir=D:\WINDOWS

D:\divelog>

====

[6304 byte] By [sneakyimpa] at [2007-10-2 18:40:34]
# 1
See if this is a help: http://java.sun.com/developer/onlineTraining/new2java/divelog/part1/page9.jsp
ChuckBinga at 2007-7-13 20:02:42 > top of Java-index,Developer Tools,Java Compiler...
# 2

in that link you posted, Problem 1 appears to be the closest thing to my problem. If you read my post closely, you can see that i have already tried compiling with a classpath.

I tried this:

javac -cp . DiveLog.java

and it returns 6 errors...all of *my* classes are missing.

I have also tried these two:

javac -cp d:\ DiveLog.java

javac -cp "D:\Program Files\Java\jdk1.5.0_06" DiveLog.java

but those result in the compiler being unable to find all the default java classes like Vector and Jbutton. I have installed and uninstalled the sdk and I have made several attempts at different PATH environment vars.

sneakyimpa at 2007-7-13 20:02:42 > top of Java-index,Developer Tools,Java Compiler...
# 3
I'm not familar with the Divelog tutoria/sample, but a guess is that you need to be issuing commands from the parent directory of the divelog directory. Try workng from the D:\ root directory.
ChuckBinga at 2007-7-13 20:02:42 > top of Java-index,Developer Tools,Java Compiler...
# 4

> in that link you posted, Problem 1 appears to be the

> closest thing to my problem. If you read my post

> closely, you can see that i have already tried

> compiling with a classpath.

>

Yes, but you did not correctly use the solution to Problem 1. The tutorial says,

If your Dive Log files are in the following directory:

C:\Applications\divelog

Step 1: cd to the divelog directory.

Step 2: Compile the Dive Log application with the following command:

javac -classpath C:\Applications\ DiveLog.java

Note the space after C:\Applications\. Because you're in the divelog directory, the compiler knows where to find DiveLog.java. The divelog package name in the file itself tells the compiler where to look for any other classes that you created as a part of that package.

So in your case, you have d:\divelog\Divelog.java. To apply the solution from the tutorial assuming the current directory is d:\divelog (pay attention to the spaces)javac -classpath d:\ DiveLog.javaChuckBing's suggestion would likely work also.

atmguya at 2007-7-13 20:02:42 > top of Java-index,Developer Tools,Java Compiler...
# 5
thanks, atmguy, but--again-- if you read my post, you'll see that i tried *exactly* what you suggested except i used the abbreviated -cp instead of -classpath. When I tried what you suggested, the compile couldn't find the built-in classes like Vector and JButton.
sneakyimpa at 2007-7-13 20:02:42 > top of Java-index,Developer Tools,Java Compiler...
# 6
remove the lib directory from your path. Might not be the cause of your problems, but it shouldn't be there.
jwentinga at 2007-7-13 20:02:42 > top of Java-index,Developer Tools,Java Compiler...
# 7

> thanks, atmguy, but--again-- if you read my post,

> you'll see that i tried *exactly* what you suggested

> except i used the abbreviated -cp instead of

> -classpath. When I tried what you suggested, the

> compile couldn't find the built-in classes like

> Vector and JButton.

I didn't see the "-classpath d:\" in your original post, but I did see it upon further review.

So if this does not work, do you mean you get the exact same error messages when you try it?

Here's the things that make it work.

1. All of the .java source call files inside the divelog directory must start with "package divelog;" statement.

2. The divelog directory is in the d:\ directory.

3. You use "javac -cp d:\ DiveLog.java" (notice the spaces)

atmguya at 2007-7-13 20:02:42 > top of Java-index,Developer Tools,Java Compiler...
# 8

it's worth noting that this java project compiled on my machine just fine before i wiped my drives and reinstalled winxp.

i have checked and double checked and want to make sure the details are clear:

1) All the java files are located in this directory:

d:\DiveLog

2) Each and every .java file in that directory contains as its first line this statement:

package divelog;

3) I have tried compiling from both d:\divelog and from d:\ (the root directory).

if i do this:

===============

cd d:\

javac -cp d:\ d:\Divelog\DiveLog.java

===============

then i get this:

===============

D:\>javac -cp d:\ d:\divelog\DiveLog.java

d:\divelog\DiveLog.java:53: cannot find symbol

symbol : class Welcome

location: class divelog.DiveLog

new Welcome(),

^

d:\divelog\DiveLog.java:58: cannot find symbol

symbol : class Diver

location: class divelog.DiveLog

new Diver(),

^

d:\divelog\DiveLog.java:63: cannot find symbol

symbol : class Dives

location: class divelog.DiveLog

new Dives(),

^

d:\divelog\DiveLog.java:68: cannot find symbol

symbol : class Statistics

location: class divelog.DiveLog

new Statistics(),

^

d:\divelog\DiveLog.java:73: cannot find symbol

symbol : class WebSite

location: class divelog.DiveLog

new WebSite(),

^

d:\divelog\DiveLog.java:78: cannot find symbol

symbol : class Resources

location: class divelog.DiveLog

new Resources(),

^

6 errors

===============

if i do it from the divelog directory:

===============

cd d:\divelog

javac -cp d:\ DiveLog.java

===============

i get this

===============

D:\DiveLog>javac -cp d:\ DiveLog.java

DiveLog.java:53: cannot find symbol

symbol : class Welcome

location: class divelog.DiveLog

new Welcome(),

^

DiveLog.java:58: cannot find symbol

symbol : class Diver

location: class divelog.DiveLog

new Diver(),

^

DiveLog.java:63: cannot find symbol

symbol : class Dives

location: class divelog.DiveLog

new Dives(),

^

DiveLog.java:68: cannot find symbol

symbol : class Statistics

location: class divelog.DiveLog

new Statistics(),

^

DiveLog.java:73: cannot find symbol

symbol : class WebSite

location: class divelog.DiveLog

new WebSite(),

^

DiveLog.java:78: cannot find symbol

symbol : class Resources

location: class divelog.DiveLog

new Resources(),

^

6 errors

D:\DiveLog>

===============

sneakyimpa at 2007-7-13 20:02:42 > top of Java-index,Developer Tools,Java Compiler...
# 9

Here's some things I can think of to try.

Some of your posts suggest that you aren't consistent in the capitalization of the directory and file names. Make sure that the directory and the package name are exactly the same and of course use the same when compiling.

Try compiling with "javac -cp d:\ divelog\*.java"

In DiveLog.java and Welcome.java, completed delete the package lines and re-type them. Then try re-compiling. If you do not get a "cannot resolve symbol" for Welcome, delete and re-type the package lines for all classes. (I am guessing at a non-displayable character.)

If all of this fails, completely remove the SDK and re-install.

atmguya at 2007-7-13 20:02:42 > top of Java-index,Developer Tools,Java Compiler...
# 10

I re-typed all the package lines.

these compile attempts still produced the six errors about missing symbols:

cd d:\

javac -cp d:\ d:\Divelog\DiveLog.java

cd d:\divelog

javac -cp d:\ DiveLog.java

your other suggestion behaved a little differently. This worked without complaining and appeared to successfully create a class for each java file. DiveLog also had DiveLog$1.class and DiveLog$2.class:

cd d:\

javac -cp d:\ divelog\*.java

but then when i tried to run the result, it failed. please recall i typed these while in d:\:

D:\>java DiveLog

Exception in thread "main" java.lang.NoClassDefFoundError: DiveLog

D:\>java DiveLog\DiveLog

Exception in thread "main" java.lang.NoClassDefFoundError: DiveLog\DiveLog (wron

g name: divelog/DiveLog)

at java.lang.ClassLoader.defineClass1(Native Method)

at java.lang.ClassLoader.defineClass(Unknown Source)

at java.security.SecureClassLoader.defineClass(Unknown Source)

at java.net.URLClassLoader.defineClass(Unknown Source)

at java.net.URLClassLoader.access$100(Unknown Source)

at java.net.URLClassLoader$1.run(Unknown Source)

at java.security.AccessController.doPrivileged(Native Method)

at java.net.URLClassLoader.findClass(Unknown Source)

at java.lang.ClassLoader.loadClass(Unknown Source)

at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)

at java.lang.ClassLoader.loadClass(Unknown Source)

at java.lang.ClassLoader.loadClassInternal(Unknown Source)

i also tried within the divelog folder:

D:\>cd d:\DiveLog

D:\DiveLog>java DiveLog

Exception in thread "main" java.lang.NoClassDefFoundError: DiveLog (wrong name:

divelog/DiveLog)

at java.lang.ClassLoader.defineClass1(Native Method)

at java.lang.ClassLoader.defineClass(Unknown Source)

at java.security.SecureClassLoader.defineClass(Unknown Source)

at java.net.URLClassLoader.defineClass(Unknown Source)

at java.net.URLClassLoader.access$100(Unknown Source)

at java.net.URLClassLoader$1.run(Unknown Source)

at java.security.AccessController.doPrivileged(Native Method)

at java.net.URLClassLoader.findClass(Unknown Source)

at java.lang.ClassLoader.loadClass(Unknown Source)

at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)

at java.lang.ClassLoader.loadClass(Unknown Source)

at java.lang.ClassLoader.loadClassInternal(Unknown Source)

D:\DiveLog>java -cp . DiveLog

Exception in thread "main" java.lang.NoClassDefFoundError: DiveLog (wrong name:

divelog/DiveLog)

at java.lang.ClassLoader.defineClass1(Native Method)

at java.lang.ClassLoader.defineClass(Unknown Source)

at java.security.SecureClassLoader.defineClass(Unknown Source)

at java.net.URLClassLoader.defineClass(Unknown Source)

at java.net.URLClassLoader.access$100(Unknown Source)

at java.net.URLClassLoader$1.run(Unknown Source)

at java.security.AccessController.doPrivileged(Native Method)

at java.net.URLClassLoader.findClass(Unknown Source)

at java.lang.ClassLoader.loadClass(Unknown Source)

at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)

at java.lang.ClassLoader.loadClass(Unknown Source)

at java.lang.ClassLoader.loadClassInternal(Unknown Source)

D:\DiveLog>java -cp d:\ DiveLog

Exception in thread "main" java.lang.NoClassDefFoundError: DiveLog

D:\DiveLog>java -cp d:\DiveLog DiveLog

Exception in thread "main" java.lang.NoClassDefFoundError: DiveLog (wrong name:

divelog/DiveLog)

at java.lang.ClassLoader.defineClass1(Native Method)

at java.lang.ClassLoader.defineClass(Unknown Source)

at java.security.SecureClassLoader.defineClass(Unknown Source)

at java.net.URLClassLoader.defineClass(Unknown Source)

at java.net.URLClassLoader.access$100(Unknown Source)

at java.net.URLClassLoader$1.run(Unknown Source)

at java.security.AccessController.doPrivileged(Native Method)

at java.net.URLClassLoader.findClass(Unknown Source)

at java.lang.ClassLoader.loadClass(Unknown Source)

at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)

at java.lang.ClassLoader.loadClass(Unknown Source)

at java.lang.ClassLoader.loadClassInternal(Unknown Source)

something seems to be pretty darn wrong. I will try to reinstall the JDK now.

sneakyimpa at 2007-7-13 20:02:42 > top of Java-index,Developer Tools,Java Compiler...
# 11

I reinstalled JDK 1.5.0.06. NO DICE.

FYI, I was able to create a new project with NetBeans and import my existing code without any changes. It compiled just fine so I know it's not my code. I was sincerely hoping to get a detailed understanding of how to code Java by hand without an IDE before choosing an IDE.

*something* is preventing JDK from compiling my project properly. I'm nearly certain I have set my java_home and path environment vars correctly and I have typed the compile commands with every combination and permutation of case available.

Is it a problem that my system is on my D drive rather than my C drive? Perhaps there is a problem with the JDK?

sneakyimpa at 2007-7-13 20:02:42 > top of Java-index,Developer Tools,Java Compiler...
# 12

PROGRESS:

since all the package declarations were all lowercase, I tried changing the name of my directory from d:\DiveLog to d:\divelog

this helped the compile problem. This compile command now works fine:

cd d:\divelog

javac -classpath d:\ DiveLog.java

HOWEVER, i still cannot get the resulting to run.

I tried all the following:

D:\Documents and Settings\Jaithe>cd d:\divelog

D:\divelog>java DiveLog

Exception in thread "main" java.lang.NoClassDefFoundError: DiveLog (wrong name:

divelog/DiveLog)

at java.lang.ClassLoader.defineClass1(Native Method)

at java.lang.ClassLoader.defineClass(Unknown Source)

at java.security.SecureClassLoader.defineClass(Unknown Source)

at java.net.URLClassLoader.defineClass(Unknown Source)

at java.net.URLClassLoader.access$100(Unknown Source)

at java.net.URLClassLoader$1.run(Unknown Source)

at java.security.AccessController.doPrivileged(Native Method)

at java.net.URLClassLoader.findClass(Unknown Source)

at java.lang.ClassLoader.loadClass(Unknown Source)

at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)

at java.lang.ClassLoader.loadClass(Unknown Source)

at java.lang.ClassLoader.loadClassInternal(Unknown Source)

D:\divelog>java -classpath . DiveLog

Exception in thread "main" java.lang.NoClassDefFoundError: DiveLog (wrong name:

divelog/DiveLog)

at java.lang.ClassLoader.defineClass1(Native Method)

at java.lang.ClassLoader.defineClass(Unknown Source)

at java.security.SecureClassLoader.defineClass(Unknown Source)

at java.net.URLClassLoader.defineClass(Unknown Source)

at java.net.URLClassLoader.access$100(Unknown Source)

at java.net.URLClassLoader$1.run(Unknown Source)

at java.security.AccessController.doPrivileged(Native Method)

at java.net.URLClassLoader.findClass(Unknown Source)

at java.lang.ClassLoader.loadClass(Unknown Source)

at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)

at java.lang.ClassLoader.loadClass(Unknown Source)

at java.lang.ClassLoader.loadClassInternal(Unknown Source)

D:\divelog>java -cp d:\ DiveLog

Exception in thread "main" java.lang.NoClassDefFoundError: DiveLog

D:\divelog>java -cp d:\ divelog

Exception in thread "main" java.lang.NoClassDefFoundError: divelog

D:\divelog>java -cp d:\ DiveLog

Exception in thread "main" java.lang.NoClassDefFoundError: DiveLog

D:\divelog>

sneakyimpa at 2007-7-13 20:02:42 > top of Java-index,Developer Tools,Java Compiler...
# 13

AHA!!!

I finally tried the magic command:

D:\>java -cp . divelog.DiveLog

OBVIOUSLY it is my limited understanding of how class names, directories, class paths, and package names are resolved by the compiler and by the java runtime.

Is there somewhere I can learn about this?

sneakyimpa at 2007-7-13 20:02:42 > top of Java-index,Developer Tools,Java Compiler...
# 14

Glad to see that the immediate problem is resolved.

Refer to this thread and read my post; then read the documentation that I referenced - that should help you resolve the problem.

http://forum.java.sun.com/thread.jspa?threadID=735358

Dot't try to continue without gaining this basic knowledge - being able to use the classpath and package statements are necessary to master Java.

ChuckBinga at 2007-7-13 20:02:42 > top of Java-index,Developer Tools,Java Compiler...
# 15

Thanks Chuck! Let me first say how much I appreciate the help.

But I've read that documentation page you referenced a number of times. What it does NOT mention is that the directory name MUST match the package name EXACTLY - it is case sensitive. While this may be par for the course on a linux or sun machine, windows generally speaking is not case-sensitive when it comes to file system stuff. apparently the java compiler is more finicky than the windows file system.

Those docs were no help at all in helping me locate that particular problem. It would be helpful if they pointed out the importance of case sensitivity in the directory names either in the tutorial or the troubleshooting section.

Also, item 4 under 'compile problems' is not clear at all. Given that we are taking ALL source directly from the tutorial, it would not make sense for methods to be called from the wrong place. That would be a flaw in either the provided source or in the tutorial itself. Furthermore, no example of exactly what 'compile error' might appear is given. I don't even know if I encountered this error or not.

The other thread looks quite helpful. I'll be reading that. Thank you.

Generally speaking, I really like the the platform documentation:

http://java.sun.com/j2se/1.3/docs/api/index.html

But all the 'getting started' material around here is pretty poorly organized, poorly edited (spelling and grammar errors etc.) and poorly formatted. Sun would do well to organize their documentation like the php documentation which has plenty of examples and useful anecdotal contributions by users:

http://php.net

Thanks for all the help guys. Without you, I'd probably be completely lost.

sneakyimpa at 2007-7-20 23:48:52 > top of Java-index,Developer Tools,Java Compiler...