File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Reflection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Reflection" Watch "Reflection" New topic


Stephen Murphy

Joined: Feb 26, 2004
Posts: 24
I am having a problem with reflection. I keep getting a NullPointerException and can't figure out why.
It is happening when I call this:

I can't figure out what the problem is. I had this reflection working, and then I made some changes to how the argument array was created. In the end, the argarray is the same.
Any ideas?
Stephen Murphy

Joined: Feb 26, 2004
Posts: 24
Also, the API for the method class says that a NullPointerException is thrown if the object in the first argument is null. I have tested for this, and it is not null.
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24195

Plain and simple: something is null. The stack trace would go along way toward pinning this down. If the top frame is in this file, on this line, then "method" is null. If it's an InvocationTargetException and the contained exception is null, then one of the arguments is probably null and shouldn't be. If the top frame is in invoke() itself, then one of the two arguments to invoke() is likely null, or your passing a "null" for a primitive type in "argArray".

If you can't puzzle it out this way, putting in a bunch of print statements to print your variables would be a help.

[Jess in Action][AskingGoodQuestions]
Stephen Murphy

Joined: Feb 26, 2004
Posts: 24
Thanks for the reply. Turns out that argArray was null. It was the very last thing I checked. Apparently I screwed up the loop that build the argArray and it was just filling up with nulls.

Thanks for the reply.
I agree. Here's the link:
subject: Reflection
jQuery in Action, 3rd edition