Win a copy of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications this week in the Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Servlet Code Throwing NullPointerException  RSS feed

 
Steve Dyke
Ranch Hand
Posts: 1779
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am needing help trying to figure out why the following throws a NullPointerException on line 19.

 
Campbell Ritchie
Marshal
Posts: 56186
171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apart from the lengths of the lines: Either ncr or ncr.getIreportpath() is null assuming I have got the right line 19. Try this as line 18½:-
System.out.printf("ncr and ncr.getIreportpath() are not null: %b %b%n",
      ncr, ncr.getIreportpath());

Such a line would normally print ...true true
If that line throws the Exception it will be ncr.getIreportpath() which is null. Don't know why either is null.
 
Steve Dyke
Ranch Hand
Posts: 1779
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Apart from the lengths of the lines: Either ncr or ncr.getIreportpath() is null .


Sorry it has taken so long to respond.

Wouldn't line 4 prevent code from processing if the ncr was returning null.

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66255
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Btw, poor form to fetch the scoped variable twice from the session. Capture them first into variables, then test them for null.
 
R K Singh
Ranch Hand
Posts: 5390
1
Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the type of ncr ?

It is not declared in the lines you posted here.
I think you want to use incr reference variable at line 19.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!