• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Starting Java: Hava a Classpath problem

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have the following Classpath

*******************************************************************
CLASSPATH=C:\Users\Beatrice\Documents\NetBeansProjects\DotComBust\src\dotcombust
\;C:\Program Files\Java\jre6\lib\ext\QTJava.zip;C:\Program Files\Java\jdk1.6.0_3
0\bin;c:\testProject
*******************************************************************************

I have already compiled GameHelper.java to GameHelper.class AND
DotCom.java to DotCom.class and both C;ass files INTO
c:\testProject

Now I try to compile DotComBust.java also in c:\testProject which implements the previous 2 classes(GameHelper+DotCom), but it gives me compile errors on all references to GameHelper and DotCom.

****************************************************************************************
C:\testProject>javac -cp . DotComBust.java
DotComBust.java:21: cannot find symbol
symbol : class GameHelper
location: class dotcombust.DotComBust
private GameHelper helper = new GameHelper();
^
DotComBust.java:22: cannot find symbol
symbol : class DotCom
location: class dotcombust.DotComBust
private ArrayList<DotCom> dotComList = new ArrayList<DotCom>();
^
DotComBust.java:21: cannot find symbol
symbol : class GameHelper
location: class dotcombust.DotComBust
private GameHelper helper = new GameHelper();
^
DotComBust.java:22: cannot find symbol
symbol : class DotCom
location: class dotcombust.DotComBust
private ArrayList<DotCom> dotComList = new ArrayList<DotCom>();
^
DotComBust.java:27: cannot find symbol
symbol : class DotCom
location: class dotcombust.DotComBust
DotCom one = new DotCom();
^
DotComBust.java:27: cannot find symbol
symbol : class DotCom
location: class dotcombust.DotComBust
DotCom one = new DotCom();
^
DotComBust.java:29: cannot find symbol
symbol : class DotCom
location: class dotcombust.DotComBust
DotCom two = new DotCom();
^
DotComBust.java:29: cannot find symbol
symbol : class DotCom
location: class dotcombust.DotComBust
DotCom two = new DotCom();
^
DotComBust.java:31: cannot find symbol
symbol : class DotCom
location: class dotcombust.DotComBust
DotCom three = new DotCom();
^
DotComBust.java:31: cannot find symbol
symbol : class DotCom
location: class dotcombust.DotComBust
DotCom three = new DotCom();
^
DotComBust.java:38: cannot find symbol
symbol : class DotCom
location: class dotcombust.DotComBust
for (DotCom dotComToSet : dotComList) {
^
11 errors
**************************************************************************************************************************

I have the correct classpath, but JAVAC isn't finding the classes.
I've tried javac -cp . DotComBust.java.
Any help would be appreciated?

 
Bartender
Posts: 1558
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Eamon Nixon,

Welcome to CodeRanch!

It seems that you are trying to access class dotcombust.DotComBust, so you don't need to put package dotcombust in your classpath.

That is, your classpath should contain parent directory of dotcombust (instead of dotcombust itself).

I hope this helps.
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Anayonkar Shivalkar wrote: . . . That is, your classpath should contain parent directory of dotcombust (instead of dotcombust itself). . . .

Disagree.

It is usually best not to set a system classpath at all, but some applications set it for you while you aren’t watching. QuickTime is notorious for doing that. Delete the references to dotcom, test project and the jdk from the classpath. They should not be in a system classpath. If you need a classpath, you should set it with the -cp tags. If you are at the dotcom stage, you don’t yet need to know about -cp. Change your classpath to read

CLASSPATH=.;C:\Program Files\Java\jre6\lib\ext\QTJava.zip

Note the .; at the beginning. That will take you to your “current” directory as a default, which is what you usually want.
You will have to navigate to the correct directory for dotcom. I would suggest you //comment out the package names from all your dotcom classes and use the directory they are in as an unnamed package.
 
Campbell Ritchie
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And again welcome to the Ranch
 
Anayonkar Shivalkar
Bartender
Posts: 1558
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Disagree.


So, problem is not with classpath? And parent directory should not be part of classpath?
 
Campbell Ritchie
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There probably is a problem with the classpath, but the ideal system classpath is completely empty. Lots of books advise you to set a system classpath, but that is usually mistaken and usually does more harm than good. If beginners download code with package names in, the package names tend to confuse them because compiling packages is awkward without Ant or an IDE. So the best thing for beginners is not to set a classpath at all, and use the current directory as an unnamed package.

Once you start using more than about a dozen classes, you are out of the realms of small applications (as it said in that Java™ tutorials link I posted), and that is the point to start learning about packages. Probably the point to start learning to use an IDE, too. When you start writing large applications which require downloaded .jars (or similar) along with your application, those resources will be stored somewhere on your computer, and you need to add those .jars to your classpath. But they will be different for each application, so you need a new classpath for each application.
 
Anayonkar Shivalkar
Bartender
Posts: 1558
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes. I agree with that. Its much better to use -cp instead of CLASSPATH env variable.
 
Campbell Ritchie
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Eamon Nixon
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:

Anayonkar Shivalkar wrote: . . . That is, your classpath should contain parent directory of dotcombust (instead of dotcombust itself). . . .

Disagree.

It is usually best not to set a system classpath at all, but some applications set it for you while you aren’t watching. QuickTime is notorious for doing that. Delete the references to dotcom, test project and the jdk from the classpath. They should not be in a system classpath. If you need a classpath, you should set it with the -cp tags. If you are at the dotcom stage, you don’t yet need to know about -cp. Change your classpath to read

CLASSPATH=.;C:\Program Files\Java\jre6\lib\ext\QTJava.zip

Note the .; at the beginning. That will take you to your “current” directory as a default, which is what you usually want.
You will have to navigate to the correct directory for dotcom. I would suggest you //comment out the package names from all your dotcom classes and use the directory they are in as an unnamed package.


Great Stuff..
//commented the package reference
Added .; as current directory classpath and deleted the others.
Thanks for tutorial link on packages also. I do read these things.
Works perfectly, never would have figured it out. Forums, wonderful places.
Great Welcome gentlemen.
Thanks for your help. Can move on to next 5 meter wall now. Then, I'll be back.
Dont worry ranch hands, I search the forums for answers before I post.
 
Campbell Ritchie
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Eamon Nixon wrote: . . . Can move on to next 5 meter wall now. . . .

It will be the next 5″ wall that catches you out

And you’re welcome We have all seen such problems before.
 
reply
    Bookmark Topic Watch Topic
  • New Topic