File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes importing a package Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "importing a package" Watch "importing a package" New topic
Author

importing a package

Oceana Wickramasinghe
Ranch Hand

Joined: Mar 02, 2011
Posts: 77
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?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60782
    
  65

You need to specify com.lost.*.

com.* will not recurse to lower packages.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Oceana Wickramasinghe
Ranch Hand

Joined: Mar 02, 2011
Posts: 77
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.
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4343
    
    8

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.
 
subject: importing a package
 
Similar Threads
Package compilation - urgent
Exception in thread "main"
Package doesn't exists - error!!- How to resolve?
File Not found exception..
Problem calling a simple program