• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Reflection  RSS feed

 
Greenhorn
Posts: 24
  • 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
  • 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.
 
author and iconoclast
Posts: 24203
43
Chrome Eclipse IDE Mac OS X
  • 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
  • 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.
 
passwords must contain 14 characters, a number, punctuation, a small bird, a bit of cheese and a tiny ad.
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!