Find out what variable is throwing a NullPointerException programatically
- by Hectoret
I know I can find out if a variable is null in Java using these techniques:
if (var==null) - too much work
try { ... } catch (NullPointerException e) { ...} - it tells me what line is throwing the exception
using the debugger - by hand, too slow
Consider this line of code:
if (this.superSL.items.get(name).getSource().compareTo(VIsualShoppingList.Source_EXTRA)==0) {
I would like to know if there's a generic way to find out programatically what variable (not just the line) is throwing the NullPointerException in a certain area of code. In the example, knowing that