• 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

package importing problem

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a java program called Balance.java which I have saved in H:\myPack.

I compiled and kept my Balance.class file in H:\myPack.
now I have another program (TestBalance.java saved in H:\> )which is using Balance.java program

while compileing I am geting the following error
H:\>javac TestBalance.java
TestBalance.java:1: package myPack does not exist
import myPack.*;
^
TestBalance.java:6: cannot resolve symbol
symbol : class Balance
location: class TestBalance
Balance test = new Balance("Johnosn", 1000.0);
^
TestBalance.java:6: cannot resolve symbol
symbol : class Balance
location: class TestBalance
Balance test = new Balance("Johnosn", 1000.0);
^
3 errors
----------------------------------
but I can able to run the code if I include the Balance class inside the TestBalance.java file.
like

I doubt some how my code is not able to locate the package, is this may be due to some 'CLASSPATH' setting? not able to find out!
Thanks in advance
Regards
Johnson
 
Ranch Hand
Posts: 366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Johnson,
It seems there is a CLASSPATH problem. IN order for a package to be found, the classpath should be till before the directory. In your example. the classpath should consist of the path till H:\
even though the .class file is in H:\mypath.
Hope this helps
Sri
 
Ranch Hand
Posts: 298
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, try setting the classpath to the H, but i think it should compile, the compiler tries to find it without the class path!!! maybe there is something wrong with your compiler!!! I tested on j2sdk 1.4, and it works, i did not set the classpath to the directory.
 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This should help:Mastering the Java classpath
 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One thing to remember is that importing stuff is all about where the class files are and that your classpath points the "root" for the packages you want to use.
Where your source code is really doesn't matter (except in some project build master's / source control nazi's head...but I'm getting off topic here).
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic