• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Listing packages using Package class

 
Bala Raj
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes I am loading all the classes.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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".
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic