File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Listing packages using Package class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Listing packages using Package class" Watch "Listing packages using Package class" New topic
Author

Listing packages using Package class

Bala Raj
Ranch Hand

Joined: Sep 12, 2000
Posts: 75
I am trying to list all of the packages using

It listed all the standard packages like java.lang, java.util, etc. When I am trying to list java.rmi, javax.swing or my packages, it’s throwing out NullPointerException.
Can some one throw light on this??
Thanks in advance,
Bala
Joe Gilvary
Ranch Hand

Joined: May 11, 2001
Posts: 152
The API docs for Package say

Package objects contain version information about the implementation and specification of a Java package.
This versioning information is retrieved and made available by the ClassLoader instance that loaded the
class(es). Typically, it is stored in the manifest that is distributed with the classes.

Did you load any classes from rmi, Swing, or your
own stuff?
Thanks,
Joe
Joe Gilvary
Ranch Hand

Joined: May 11, 2001
Posts: 152
The API docs for Package say

Package objects contain version information about the implementation and specification of a Java package.
This versioning information is retrieved and made available by the ClassLoader instance that loaded the
class(es). Typically, it is stored in the manifest that is distributed with the classes.

Did you load any classes from rmi, Swing, or your
own stuff?
Thanks,
Joe
Bala Raj
Ranch Hand

Joined: Sep 12, 2000
Posts: 75
Yes I am loading all the classes.
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
All of them? Ummm... how are you doing that? Mentioning them in import statements will not be enough to cause them to be loaded - you need to actually use the class somehow. A simple approach might be:

or

We don't really need the name, and aren't even bothering to remember it. This just qualifies as a "use".


"I'm not back." - Bill Harding, Twister
 
wood burning stoves
 
subject: Listing packages using Package class