• 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
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

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: 62231
193
  • 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: 62231
193
  • 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.
 
We don't have time to be charming! Quick, read this tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!