File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reflection

 
Stephen Murphy
Greenhorn
Posts: 24
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 24
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Stephen Murphy
Greenhorn
Posts: 24
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic