• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

NullPointerException...

 
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm getting a java.lang.NullPointerException and I can't figure out why. Here is the Stack Trace. Its happening at line 63 in my doPost of my servlet..



This is the code...



the problem is in the else statement, I just don't know why my getServletContext() is causing this error...
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which is line 63?
 
Bryce Martin
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Its the getServletContext() in my else statement.
 
Sheriff
Posts: 67746
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
Here's your problem:

You override the base init and discard the passed config. So it never gets stored and you get an NPE when you try to access it.

The rules:

1) Don't override init if you don't have anything to do.

2) If you do have somethig to do, override the parameterless init().

See the Servlets FAQ for more info.
[ November 21, 2007: Message edited by: Bear Bibeault ]
 
Bryce Martin
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just figured that out and when I came here to post it that is exactly what you had just said. I had started coding my servlet from an example I had found somewhere online, and they had overridden the init(). I didn't have anything to override so I just left it sitting there blank like you would expect of a greenhorn.

I got it to forward on, but when I do the "<p>$(modelBean.Po)</p>" in my jsp it actually prints out "$(modelBean.Po)". Now I assumed that this was some sort of value reference. How exactly do I access my bean data? Or should I, instead of writing a bean, just set a session attribute. I found that doing a session.setAttribute from within my FormManager controller doesn't work. The Simple MVC example uses a bean to control data, so that is what I did to get it working.

My results.jsp page looks like this...



Am I missing something? I just want to see the values and prove that things are working before I go ahead and start to implement more of my logic.

Thanks for the help
Bryce
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
EL expressions use curly braces.
${}

not parenthesis
 
Bryce Martin
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yep, my eyes deceived me when I looked at the example code. My font is pretty small and {} looks a lot like (). Thanks!
 
Heroic work plunger man. Please allow me to introduce you to this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic