This week's book giveaway is in the Python forum.
We're giving away four copies of Python Continuous Integration and Delivery and have Moritz Lenz on-line!
See this thread for details.
Win a copy of Python Continuous Integration and Delivery this week in the Python forum!
  • 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
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

Why removing a package declaration allows the code to compile  RSS feed

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I removed "package chap05;" from all the files and it got compiled without any error. I don't have an explanation as to why this worked.
I also commented out
//import chap05.GameHelper;

P.S: I am using cmd to compile and run.

If anybody has an answer to why removing the package declaration worked, please leave a comment.

Thanks!
 
Marshal
Posts: 63391
205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

If you use package names, you need to compile from inside the package, or you need to state the path to the .java file. Not
myFolder>/ javac MyClass.java
but
myPackage>/ javac MyClass.java
or
myFolder>/ javac myPackage/MyClass.java

Also, the compiler will expect the XXX.class files in your other packages to have been compiled already before you can execute the imports. You need there to be an XXX.class file before you compile its client code.

I can't give you any more details because I don't know the instructions you are using to try to compile your code.
 
Campbell Ritchie
Marshal
Posts: 63391
205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This question merits a thre‍ad of its own; I split it from this discussion.
 
See ya later boys, I think I'm in love. Oh wait, she's just a tiny ad:
Become a Java guru with IntelliJ IDEA
https://www.jetbrains.com/idea/
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!