Title: RE: getServletContext () throws NullPointerException

Are you concatenating anything else when writing to sc.log("blabla" + variable);

This might throw a NullPointerException if the variable is <null>.  Make sure when concatenating anything that the variable is not null when using the (+) operator.  I usually use the String.concat method.  It allows passing in a <null> and returns a "".

For what that was worth, maybe it helped you.

Thanks,

Nick Neuberger

-----Original Message-----
From: Andreas Jerke [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, January 18, 2000 11:25 AM
To: '[EMAIL PROTECTED]';
'[EMAIL PROTECTED]'
Subject: getServletContext () throws NullPointerException


Hi,

I searched the FAQ but could not find an answer:

my system:

win nt 4.0
apache 1.3
jserv 1.0

I am developing webapplications with servlets. For
debugging I use getServletContext:

****
....
public ServletContext sc = getServletContext()
...
sc.log("blabla")
...
sc.log(myException,"blabla")
****

But when I start the Servlet, I get a NullPointerException:
****
java.lang.NullPointerException:
        at javax.servlet.GenericServlet.getServletContext(GenericServlet.java:67)
        at javax.servlet.GenericServlet.log(GenericServlet.java:116)
        at javax.servlet.GenericServlet.destroy(GenericServlet.java:213)
        at org.apache.jserv.JServServletManager.destroyServlet(Compiled Code)
        at org.apache.jserv.JServServletManager.destroyServlets(Compiled Code)
        at org.apache.jserv.JServServletManager.checkReload(JServServletManager.java)
        at org.apache.jserv.JServConnection.processRequest(JServConnection.java)
        at org.apache.jserv.JServConnection.run(JServConnection.java)
        at java.lang.Thread.run(Thread.java:479)
****
My servlets work fine if I don't use getServletCOntext, but I would like
to use it ...

bye

Andreas


------------------------------------------------------------
To subscribe:    [EMAIL PROTECTED]
To unsubscribe:  [EMAIL PROTECTED]
Problems?:       [EMAIL PROTECTED]

Reply via email to