• 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

compiling package with import statement

 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've been trying to get this working .... I have 2 classes where one class uses an import statement.

My file structure is c:\Sierra\java where both the Goo and Sludge java files are located. I can compile Sludge using c:\Sierra\java> javac -d c:\Sierra\classes Sludge.java and class Sludge is correctly created in the cert folder. When I try to do the same with Goo, I get compile errors: "package cert does not exist" and "cannot resolve symbol" when it attempts to create an instance of Sludge.
I am using 1.4.1 compiler. What am I doing wrong? I was trying to keep my class vs java files in separate as recommended in previous posts.
[ March 28, 2003: Message edited by: Linda Pan ]
 
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you can't have two classes in different packages be defined in the same file.
Try breaking it up to two files -- and all should be fine.
 
Linda Pan
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got it working ... it appears as long as I have Sludge in the cert subdirectory, and Goo in the book subdirectory, I can compile both files using c:\Sierra\java> javac cert/Sludge.java book/Goo.java. I can run java book/Goo and get my output.
 
Linda Pan
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was also working with source files in the c:\Java path. When compiling I would get the class not found compile error. Resolved my problem by setting the classpath in autoexec.bat file.
 
Let's get him boys! We'll make him read this tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic