• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

errors in importing packages.  RSS feed

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have file structre like this :
c:\javapractice\one\SomeFile.java
and
c:\javapractice\another\SomeOtherFile.java



Now when i try to compile SomeFile.java using the command
c:\javapractice\one>javac SomeFile.java
it compiles fine.
But when i try to compile SomeOtherFile.java using the command
c:\javapractice\another>javac SomeOtherFile.java
it gives the error
package one doesn't exist
import one.SomeFile;

After some study i got to know that this can be the problem associated with classpath....,but still i am not able to fix it.
Please suggest some remedy.
 
Bartender
Posts: 4179
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a classpath issue. The classpath is the folder under which all of your packages and classes can be found. You have two packages, one and another. These two packages are both in C:\javapractice, so C:\javapractice needs to be in your classpath. Here is how you do it:

1: Navigate to C:\javapractice\ to do all your compiling (the root of your classpath).
2: Type in javac -cp . one\SomeFile.java
-- the -cp sets the classpath, then a space then a period. The period means 'this folder'. So -cp . means 'set the classpath to the current folder'
3: Type in javac -cp . another\SomeOtherFile.java
-- since -cp was set to C:\javapractice, the compiler knows to start looking there for one.SomeFile.class
 
Dushyant Shukla
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Steve sir.
The problem is resolved.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!