Link to home
Start Free TrialLog in
Avatar of ericr29
ericr29

asked on

java.lang.NullPointerException - Cannot Understand Why.

The code below compiles but I keep getting a "java.lang.NullPointerException" error on line 72 at runtime.

Can someone tell me why?  This code calls a .jcx (control) file to query a database and return a RowSet.
package Main.pdfGen;
 
import Main.cntrls.*;
import com.bea.wlw.netui.pageflow.Forward;
import com.bea.wlw.netui.pageflow.PageFlowController;
import java.io.*;
 
//iText imports
import com.lowagie.text.*;
import com.lowagie.text.pdf.*;
 
import javax.sql.RowSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import javax.naming.NamingException;
             
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
 
/**
 * @jpf:controller
 * @jpf:view-properties view-properties::
 * <!-- This data is auto-generated. Hand-editing this section is not recommended. -->
 * <view-properties>
 * <pageflow-object id="pageflow:/Main/pdfGen/PdfGenController.jpf"/>
 * <pageflow-object id="action:begin.do">
 *   <property value="80" name="x"/>
 *   <property value="100" name="y"/>
 * </pageflow-object>
 * </view-properties>
 * ::
 */
public class PdfGenController extends PageFlowController
{
    public search searchCNTRL;
    public RowSet pdfRowSet;
 
    /**
     * This method represents the point of entry into the pageflow
     * @jpf:action
     */
    protected Forward begin()throws IOException,SQLException,NamingException
    {   
        HttpServletResponse res;
        HttpServletRequest req;
        ServletOutputStream out;
        res = this.getResponse();
        req = this.getRequest();
        
        res.setContentType("text/HTML");
        out = res.getOutputStream();
        
        String report = req.getParameter("report");
        String dir = req.getParameter("dir");
        String field = req.getParameter("field");
        String value = req.getParameter("value");
        String cnt = req.getParameter("cnt");                                
        
        /*out.print("<html><head></head><body>");
        out.print("Report: " + report + "<br/>");
        out.print("Dir: " + dir + "<br/>");
        out.print("Field: " + field + "<br/>");
        out.print("Value: " + value + "<br/>");
        out.print("Cnt: " + cnt + "<br/>");                                
        out.print("<html><head></head><body>");*/
        
        if(report.equalsIgnoreCase("report_1")){
            // Get DB rows
            pdfRowSet = searchCNTRL.getReportRows(value,"lower(column)","ORDER BY column ASC",0,Integer.parseInt(cnt));  
        }
        
        out.flush();
        out.close();
                
        return null;
    }
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of ksivananth
ksivananth
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I'm not familiar with the "search" class, but it probably needs to be initialized, which I don't see happening.  searchCNTRL is probably a NULL object at line 72 and thus the error occurring.  You probably need something along the lines of:

searchCNTRL = new search();

..before you use any methods of searchCNTRL.  Hope this works.
Avatar of ericr29
ericr29

ASKER

So the code above would be changed to look like this:
public class PdfGenController extends PageFlowController
{
    public search searchCNTRL;
    searchCNTRL = new search();
    public RowSet pdfRowSet;
 
...

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial