• 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:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

importing a package  RSS feed

 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys, i been trying to import a package but it wont work

I got my files on D drive, folder "project1". And also i use Jcreator.

My first program



now the package com is created inside project1 folder, the source file is in the same folder.

And i created another program



the source file is in the same folder, project1.

but when i try to compile it i get a compiler error "package com does not exist"

but if i change my program into this



It compiles without any errors. Simply put i cant import the entire package. I can only import the specific class. What am i doing wrong here?
 
Author and ninkuma
Marshal
Posts: 66787
168
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to specify com.lost.*.

com.* will not recurse to lower packages.
 
Oceana Wickramasinghe
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Bear Bibeault wrote:You need to specify com.lost.*.

com.* will not recurse to lower packages.



Thank you, it worked. But can you please explian further. Why does this happen.
 
Bartender
Posts: 4568
9
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java packages have a hierarchical naming convention, but they're not actually hierarchical. So the com.lost package isn't part of the com package. You have to import each package explicitly.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!