|
-
August 15th, 2012, 01:20 PM
#1
A particularly nasty java.lang.NullPointerException
Can anybody help me I am having trouble with this code:
Code:
void getDisplayLifeReviewForHome() {
System.err.println ("Can't Find Display Life Review for Home !!! " );
}
void getDisplayLifeReviewForUser() {
System.err.println ("Can't Find Display Life Review for User !!! " );
}
public String getDisplayLifeReviewForUser( BcSQLAgent agt ) throws Exception
{
if (getDisplayLifeReviewForHome( agt ).equals( TRUE ))
{
if (_displayLifeReviewForUser == null)
{
_loadUserValues( agt );
}
return _displayLifeReviewForUser;
}
else
{
return FALSE;
}
} // getDisplayLifeReviewForUser()
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
It is erroring on
public String getDisplayLifeReviewForUser( BcSQLAgent agt ) throws Exception
and it doesn't matter if I set it to TRUE or FALSE.
Thanks,
-
August 15th, 2012, 02:53 PM
#2
Re: A particularly nasty java.lang.NullPointerException
Have a look at these two lines of your code:
Code:
void getDisplayLifeReviewForHome()
and
Code:
if (getDisplayLifeReviewForHome( agt ).equals( TRUE ))
In the second of these lines you are invoking the equals() method from whatever is returned by the getDisplayLifeReviewForHome() method. Now, what kind of object is this method returning?
-
August 15th, 2012, 03:30 PM
#3
Re: A particularly nasty java.lang.NullPointerException
Hello this object is:
cached DISPLAY_LIFE_REVIEW flag for home.
Also, I put that method in there on the fly to see if it would pass and print an error
(void getDisplayLifeReviewForHome())
However, this belongs to the following method in reality:
public final class Context -- master class object.
-
August 15th, 2012, 07:00 PM
#4
Re: A particularly nasty java.lang.NullPointerException
Do you mean that the code you posted is not the code that's raising the exception? Why don't you post the actual code?
-
August 15th, 2012, 10:22 PM
#5
Re: A particularly nasty java.lang.NullPointerException
Well the stack trace says this:
2012-08-09 10:56:52,473 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/].[SelectReporting]] Servlet.service() for servlet SelectReporting threw exception
java.lang.NullPointerException
at bcc.lib.Context.getDisplayLifeReviewForUser(Context.java:932)
at bcc.lib.NavBar._generateHTML(NavBar.java:145)
at bcc.lib.NavBar.getHTML(NavBar.java:114)
at bcc.lib.Context.getNavBarHTML(Context.java:1098)
at bcc.lib.BasePageJQuery.getNavBar(BasePageJQuery.java:312)
at bcc.lib.BasePageJQuery.buildPage(BasePageJQuery.java:84)
at bcc.lib.BasePageJQuery.doServletFunction(BasePageJQuery.java:42)
at bcc.lib.BaseBccServlet.doPost(BaseBccServlet.java:102)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
at java.lang.Thread.run(Thread.java:595)
The servlet code is here that is throwing the exception:
package bcc.pages;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
import com.bc.util.BcSQLAgent;
import com.bc.util.logging.Logger;
import bcc.lib.Context;
import bcc.lib.dob.Case;
import bcc.lib.dob.CaseDMDocuments;
import bcc.lib.dob.Home;
import bcc.lib.dob.TransFiles;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
public class SelectReporting extends bcc.lib.BasePageJQuery
{
protected String getBanner( Context ctx, BcSQLAgent agt, HttpServletRequest req )
{
return "General Reports";
}
protected String getContent( Context ctx, BcSQLAgent agt, HttpServletRequest req, HttpServletResponse res ) throws Exception
{
try
{
StringBuffer sb = new StringBuffer();
sb.append("<Reports>");
addStateInformation(sb, ctx);
Home h = ctx.getHome(agt);
h.getXML(sb);
sb.append( "</Reports>" );
Logger.finest( this, "getContent", "XML =\n" + sb.toString() );
return ctx.parseStylesheet( agt, "SelectReporting.xsl", sb );
}
catch ( Exception e )
{
throw e;
}
}
protected String getNavBarItem( Context ctx, BcSQLAgent agt, HttpServletRequest req ) throws Exception
{
return "SelectReporting";
}
}
-
August 15th, 2012, 11:46 PM
#6
Re: A particularly nasty java.lang.NullPointerException
Still not the code throwing the exception. Read the stack trace again; it says that the NullPointerException was thrown at line 932 of the class bcc.lib.Context, especifically when executing the method getDisplayLifeReviewForUser. I don't see that class or the method in the code posted (I may have missed it though because you didn't use code tags and the indentation was lost).
Now, have a look at line 932 of bcc.lib.Context. There you must be using at least one instance of an object. Just apply some elementary debugging technic and print a message just before that line to let you know if that (or those if more than one) instance refers to null.
Then trace where that instance is supposed to be created and you will probably find the actual cause of the error.
-
August 16th, 2012, 05:58 AM
#7
Re: A particularly nasty java.lang.NullPointerException
Hello I understand everything you are saying except the last part:
"Then trace where that instance is supposed to be created and you will probably find the actual cause of the error. "
Than ks,
-
August 16th, 2012, 12:36 PM
#8
Re: A particularly nasty java.lang.NullPointerException
What I mean is that you have to review your code looking for the point (before invoking the method that throws the exception) where the instance used in the method would be assigned a reference (to an object). You may find that this never happens or there is a problem further up your code where that reference is created. Without seeing your code I cannot be more specific.
In
Code:
if (getDisplayLifeReviewForHome( agt ).equals( TRUE ))
for the equals() method to work, getDisplayLifeReviewForHome( agt ) must return a reference to an object; if it is not (i.e. if it is null) then the NullPointerException is thrown.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|