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 how to use reflection when static members throw exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "how to use reflection when static members throw exception" Watch "how to use reflection when static members throw exception" New topic
Author

how to use reflection when static members throw exception

Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31076
    
233

I feel like this has been asked before and I'm not finding the right search terms. (reflection and static are too narrow.) Can someone help an internet detective?

I'm trying to use reflection to get the Class object from a string package/class name. Using Class.forName works fine for most of my classes. The few that fail have a static field that calls a method that reads from a property file. Which fails because in my test environment that property isn't there.

I can't change the code that makes the static call. (And I need reflection for some analysis on it.) Is it possible to do this? How?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19790
    
  20

Try commenting out these last two lines one by one. You can even use reflection, as long as you don't try to invoke the methods / get the field values / set the field values. But listing fields and methods, not a problem.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31076
    
233

Thank you! I would have needed classloader in my search to find it.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19790
    
  20

You're welcome
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to use reflection when static members throw exception