Null field . I got this error : java.lang.NullPointerException

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • makweatan
    New Member
    • Jun 2009
    • 11

    #1

    Null field . I got this error : java.lang.NullPointerException

    Hello guys...

    Data is not updated into table. I got this error : java.lang.NullP ointerException


    [5/24/10 10:11:24:012 SGT] 00000030 SystemErr R java.lang.NullP ointerException
    [5/24/10 10:11:24:028 SGT] 00000030 SystemErr R at my.org.hasil.dc ms.grq.dao.XC18 DAO.updateXC18( XC18DAO.java)
    [5/24/10 10:11:24:028 SGT] 00000030 SystemErr R at my.org.hasil.dc ms.grq.bo.XC18B O.processXC18(X C18BO.java)
    [5/24/10 10:11:24:028 SGT] 00000030 SystemErr R at my.org.hasil.dc ms.grq.web.XC18 Action.performS edia(XC18Action .java)
    The program :

    1.)my.org.hasil .dcms.grq.web.X C18Action.perfo rmSedia(XC18Act ion.java)


    public ActionForward performSedia(
    ActionMapping mapping,
    ActionForm form,
    javax.servlet.h ttp.HttpServlet Request request,
    javax.servlet.h ttp.HttpServlet Response response)
    {
    ActionForward forward=new ActionForward() ;
    HttpSession httpSession = request.getSess ion();
    MESSession session = (MESSession) httpSession.get Attribute(DCMSC onstants.DCMSCo nstants_MESSESS ION);
    TodoparameterFo rm todoForm=(Todop arameterForm)ht tpSession.getAt tribute("todopa ramForm");
    XC18BO xcbo=new XC18BO(session) ;
    XC18Form xc18form=(XC18F orm)form;

    try
    {
    BeanUtils.copyP roperties(xcbo, todoForm);
    BeanUtils.copyP roperties(xcbo, xc18form);
    xcbo.setTodo_id (xc18form.getId ());
    xcbo.setStatus( DCMSConstants.U SERTODO_STATUS_ SEDIA);
    xcbo.processXC1 8(); }catch(Exceptio n e)
    {
    e.printStackTra ce();
    }
    forward=mapping .findForward("s uccess");
    return forward;
    }

    2.)my.org.hasil .dcms.grq.bo.XC 18BO.processXC1 8(XC18BO.java)

    public void processXC18()
    {
    try{
    setDaoName("my. org.hasil.dcms. grq.dao.XC18DAO ");
    requestConnecti on();
    XC18DAO xcDao =(XC18DAO)getDA O();
    xcDao.insertUse rTodo(this);
    XC18DAO xcDao1 =(XC18DAO)getDA O();
    xcDao1.updateXC 18(this);
    commit();

    }

    3.) XC18BO.java

    public void updateXC18(XC18 BO xcbo) throws SQLException
    {
    String file_no=xcbo.ge tFileNo();
    if (file_no==null) file_no=xcbo.ge tFileNo();
    String it_ref_no=xcbo. getIt_ref_no();
    int taxpayer_key=xc bo.getTaxpayer_ key();
    int taxtype_key = Integer.parseIn t(xcbo.getTaxty pe_key());
    String status = xcbo.getStatus( );
    String update_field = "";
    if ( status.equals(D CMSConstants.US ERTODO_STATUS_S EDIA)
    || status.equals(D CMSConstants.US ERTODO_STATUS_P REPARE))
    {
    update_field = new StringBuffer()
    .append(" OFFICER_PREPARE = ?, ")
    .append(" DATE_PREPARE = ?, ")
    .append(" STATUS = ? ")
    .toString();
    }else if( status.equals(D CMSConstants.US ERTODO_STATUS_L ULUS))
    {
    update_field = new StringBuffer()
    .append(" OFFICER_APPROVE = ?, ")
    .append(" DATE_APPROVE = ?, ")
    .append(" STATUS = ? ")
    .toString();
    }
    else if( status.equals(D CMSConstants.US ERTODO_STATUS_T OLAK))
    {
    if (file_no==null) file_no=xcbo.ge tFile_no();
    update_field = new StringBuffer()
    .append(" OFFICER_REJECT = ?, ")
    .append(" DATE_REJECT = ?, ")
    .append(" STATUS = ? ")
    .toString();
    }
    else if( status.equals(D CMSConstants.US ERTODO_STATUS_X CHEAD_TOLAK))
    {
    if (file_no==null) file_no=xcbo.ge tFile_no();
    update_field = new StringBuffer()
    .append(" OFFICER_REJECT = ?, ")
    .append(" DATE_REJECT = ?, ")
    .append(" STATUS = ? ")
    .toString();
    }
    else if( status.equals(D CMSConstants.US ERTODO_STATUS_T ERIMA))
    {
    file_no=xcbo.ge tFile_no();
    update_field = new StringBuffer()
    .append(" OFFICER_RECEIVE D = ?, ")
    .append(" DATE_RECEIVED = ?, ")
    .append(" STATUS = ? ")
    .toString();
    }

    PreparedStateme nt stmt = null;
    StringBuffer sql = new StringBuffer();
    sql.append(" UPDATE " + tableName + " SET ");
    sql.append(upda te_field);
    sql.append(" WHERE ");
    sql.append(" TAXPAYER_KEY = ?");
    sql.append(" AND FILE_NO = ?");
    sql.append(" AND TAXTYPE_KEY = ?");

    stmt = conn.prepareSta tement(sql.toSt ring());
    stmt.setString( 1, session.getUser Bo().getUser_id ());
    stmt.setTimesta mp(2, now());
    stmt.setString( 3, status);
    stmt.setInt(4, taxpayer_key);
    stmt.setString( 5, file_no);
    stmt.setInt(6, taxtype_key);
    stmt.executeUpd ate();

    }

    Where did I go wrong? It seems that the field that I need is null. How can I fill up the field with the data? Please...I'm so stucked and lost!

    TQ.
  • ThatThatGuy
    Recognized Expert Contributor
    • Jul 2009
    • 453

    #2
    Posting Such huge chunk of code. will not help
    post only the portion of the code that's creating the problem.

    Comment

    • jkmyoung
      Recognized Expert Top Contributor
      • Mar 2006
      • 2057

      #3
      Could you indicate the line in updateXC18() where you are getting the null exception?

      Side comments: I don't get why you're constantly using: file_no=xcbo.ge tFileNo();
      and expecting to get different results. But then again we have no idea what your XC18BO class looks like.

      Comment

      • makweatan
        New Member
        • Jun 2009
        • 11

        #4
        hi young, thanks for the comment...
        it seems that that lines was the problem...
        things went well after I uncomment the next lines of

        'if (file_no==null) file_no=xcbo.ge tFile_no();'.


        Thank u anyway.....

        Comment

        Working...