This topic is now archived and is closed to further replies.


[java] stupid java compiler!!!

Recommended Posts

hi im working with java for some assignments at uni and im having trouble with java on my computer at home. its set up right and all with all the classpaths and paths set and everything. but whenever i compile something that requires another user made class thats in the same directory as the one im compiling, java just gives me "cannot resolve symbol" error and its going to really hamper my work travelling between uni and back just to do an assignment... anyone got any ideas Get busy livin'' or get busy dyin''... - Shawshank Redemption

Share this post

Link to post
Share on other sites
set the classpath to you current directory as well.
check if the user class is in a package or not , because if you didnt import the user package, the compiler cant see it ...

Its my duty, to please that booty ! - John Shaft

Share this post

Link to post
Share on other sites
Hi, classpaths are a bitch!
Get netbeans [] free java ide.
It has a filesystem interface that represents your classpath, so you can easily see whats in the classpath and add directorys to it. Very cool. make life easy.

Share this post

Link to post
Share on other sites
Just to elaborate on what jwalker said:

It sounds like the user made class you are trying to use is intended as part of a package. All this means is that the first line in the source of the class is
package userthings;
or whatever the package name is. In this case the compiler expects to find the class in a folder called ''userthings'', relative to the current directory which you invoke javac from.
So you need to find out if this is the case with the user made class you want to use, and if so also in your own file you need to
import userthings;

I think the default installation of java does not include the current working directory in the default classpath. If this is the problem you can fix it on windows with:
or on linux with:

Share this post

Link to post
Share on other sites
Never set the classpath, unless you have a lot of experience and know what you are doing. This will cause the exact errors you are talking about. Remove the classpath setting and try again.

Make it work.
Make it fast.

"I’m happy to share what I can, because I’m in it for the love of programming. The Ferraris are just gravy, honest!" --John Carmack: Forward to Graphics Programming Black Book

Share this post

Link to post
Share on other sites
I''m a Sun Microsystems Java Instructor and classpath can be the most frustrating thing sometimes, but here are some tips to make sure that you don''t have any more problems. I''m assuming you are developing on windows with the Sun JDK.
Here is a quick run down of what classpath is in the first place. Classpath is where Java searches for Java classes. If you create a class called MathPlus and you define it in the package called com.util by placing the line:

package com.util;

at the top of your "" file, then the real name of the class is com.util.MathPlus. If MathPlus had a main and you tried to run it by calling "java MathPlus", you would get errors. To run the class you would have to call

java com.util.MathPlus

and Java would use the class path to find the MathPlus.class file. So when you import that class by either :

import com.util.*;
import com.util.MathPlus;

What you are really doing is telling Java that to find the MathPlus class, go through the directories that are in the classpath and look in each directory for a directory called com, then a directory called util and inside util you should find the "MathPlus.class" file. DO NOT PUT PACKAGE STRUCTURE IN THE CLASSPATH. In this example, the "com" directory would not be in the classpath, just the directory that the "com" directory sits in.

So without classpath, you are really not taking advantage of the power of Java... now here are those tips.

1) Inside you prompt check you classpath
It will probably give you something like "%CLASSPATH%" back
meaning your classpath is not set, so we will set it...

2) Choose a directory to start you packages from... for these examples I will choose "c:\jlib".
So I will make sure that my classpath has c:\jlib and the current directory.


The "." means whatever directory you called the compiler from,
"c:\jlib" is where your package directory structure will begin,
and "%CLASSPATH" so we don''t lose anything that may have been in the classpath before.

3) So now when you are going to make a Java class inside a package you will create the directories off of c:\jlib. If you want to build packages off of other directories, just add them to the classpath.

4) Lets go back to the com.util.MathPlus class for a minute. After you compile the Java file, make sure that the MathPlus.class file is in the right place. Using our c:\jlib example, MathPlus.class would end up in the "c:\jlib\com\util" directory.

5) Make sure to move the file into the same directory as the MathPlus.class file. If Java finds the .java file before it finds the .class file, it will compile the .java file for you and you probably don''t want that. Just make sure the .java file is in the same directory as the .class file and you will have no problems.

6) With a properly set classpath you can run Java files from anywhere. So to run the "com.util.MathPlus" class I would not have to be in the c:\jlib directory... as long as my class path is properly set.

Hope this helped,


"He who joyfully marches in rank and file has already earned my contempt. He has been given a large brain by mistake, since for him the spinal cord would suffice."
-Albert Einstein

Share this post

Link to post
Share on other sites
thanks for all your replies, i had a feeling that the class path was the problem all along but i just wanted confirmation.. i removed the classpath settings and everythings back to normal. now i get to do my assignments.. yay....

Get busy livin'' or get busy dyin''... - Shawshank Redemption

Share this post

Link to post
Share on other sites