[Webinar] Streamline your web hosting managementRegister Today


java.lang.NullPointerException - Cannot Understand Why.

Posted on 2008-02-11
Medium Priority
Last Modified: 2013-12-10
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();
        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("Report: " + report + "<br/>");
        out.print("Dir: " + dir + "<br/>");
        out.print("Field: " + field + "<br/>");
        out.print("Value: " + value + "<br/>");
        out.print("Cnt: " + cnt + "<br/>");                                
            // Get DB rows
            pdfRowSet = searchCNTRL.getReportRows(value,"lower(column)","ORDER BY column ASC",0,Integer.parseInt(cnt));  
        return null;

Open in new window

Question by:ericr29
  • 2
LVL 26

Accepted Solution

ksivananth earned 1000 total points
ID: 20867256
searchCNTRL is not initialized!

Expert Comment

ID: 20867258
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.

Author Comment

ID: 20867296
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


Assisted Solution

Jonez176 earned 1000 total points
ID: 20867389
Yes.  You may need to specify some parameters though.  If your IDE doesn't give you the list of constructors, consult your documentation on the "search" class.

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This exercise is about for the following scenario: Dmgr and One node with 2 application server. Each application server contains it owns application. Application server name as follows server1 contains app1 server2 contains app1 Prereq…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses
Course of the Month9 days, 10 hours left to enroll

591 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question