• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

Servlet Code Throwing NullPointerException

 
Ranch Hand
Posts: 2140
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am needing help trying to figure out why the following throws a NullPointerException on line 19.

 
Marshal
Posts: 75842
361
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2140
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Sheriff
Posts: 67645
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 5397
1
Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic