users@glassfish.java.net

NullPointerException error

From: arash_ <rezaei.arash_at_gmail.com>
Date: Sun, 27 Sep 2009 02:05:30 -0700 (PDT)

Dear All, I am a totally newbie in java and trying to use an application. I
had received the following error as the output of tomcat, could someone
please help me find out the origin of the error, I also presented here the
code for "ServletPrinter.printItemDescription" and "PutBid.doGet" after the
error.

-bash-3.2# 08:29:52,942 ERROR [PutBid]:260 - Servlet.service() for servlet
PutBid threw exception
java.lang.NullPointerException
        at
edu.rice.rubis.servlets.ServletPrinter.printItemDescription(Unknown Source)
        at edu.rice.rubis.servlets.PutBid.doGet(Unknown Source)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:743)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
        at sun.reflect.GeneratedMethodAccessor63.invoke(Unknown Source)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at
org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:244)
        at java.security.AccessController.doPrivileged(Native Method)
        at javax.security.auth.Subject.doAsPrivileged(Subject.java:517)
        at
org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:276)
        at
org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:162)
        at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:262)
        at
org.apache.catalina.core.ApplicationFilterChain.access$000(ApplicationFilterChain.java:52)
        at
org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:171)
        at java.security.AccessController.doPrivileged(Native Method)
        at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:167)
        at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
        at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
        at
org.objectweb.jonas.web.catalina55.ResetAuthenticationValve.invoke(ResetAuthenticationValve.java:107)
        at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
        at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
        at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
        at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
        at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:875)
        at
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol
.java:665)
        at
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
        at
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
        at
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
        at java.lang.Thread.run(Thread.java:595)
------------------
"ServletPrinter.printItemDescription":
  void printItemDescriptionToBuyNow(Item item, User user)
  {
    try
    {
      printHTMLheader("RUBiS: Buy Now");
      printHTMLHighlighted("You are ready to buy this item: " +
item.getName());
      
      out.println(
        "<TABLE>\n"
          + "<TR><TD>Quantity<TD><BIG>"
          + item.getQuantity()
          + "</BIG>\n"
          + "<TR><TD>Seller<TD> \"/rubis/servlet/ViewUserInfo?userId=" "
          + item.getSeller().getNickname()
          + " ( \"/rubis/servlet/PutCommentAuth?to=" Leave a comment on
this user )\n"
          + "<TR><TD>Started<TD>"
          + item.getStartDate()
          + "\n"
          + "<TR><TD>Ends<TD>"
          + item.getEndDate()
          + "\n"
          + "</TABLE>");
      
      printHTMLHighlighted("Item description");
      out.println(item.getDescription());
      out.println("<br><p>\n");
      
      printHTMLHighlighted("Buy Now");
      printHTML(
        "<form action=\"/rubis/servlet/StoreBuyNow\" method=POST>\n"
          + "<input type=hidden name=userId value="
          + user.getId()
          + ">\n"
          + "<input type=hidden name=itemId value="
          + item.getId()
          + ">\n"
          + "<input type=hidden name=maxQty value="
          + item.getQuantity()
          + ">\n");
      if (item.getQuantity().intValue() > 1)
        printHTML(
          "<center><table><tr><td>Quantity:</td>\n"
            + "<td><input type=text size=5
name=qty></td></tr></table></center>\n");
      else
        printHTML("<input type=hidden name=qty value=1>\n");
      printHTML("<p><center><input type=submit value=\"Buy
now!\"></center><p>\n");
    }
    catch (Exception e)
    {
      out.println(
        "Unable to print Item description (exception: " + e + ")<br>\n");
    }
  }
-----------------
"PutBid.doGet"
  public void doGet(HttpServletRequest request, HttpServletResponse
response)
    throws IOException, ServletException
  {
    ServletPrinter sp = null;
    Session sess = null;
    User user = null;
    Item item = null;
    Float maxBid = null;
    Integer nbOfBids = null;
    
    String itemStr = request.getParameter("itemId");
    String nick = request.getParameter("nickname");
    String pass = request.getParameter("password");
    sp = new ServletPrinter(response, "PutBid");
    
    if ((itemStr == null)
      || (itemStr.equals(""))
      || (nick == null)
      || (nick.equals(""))
      || (pass == null)
      || (pass.equals("")))
    {
      printError("Item id, name and password are required - Cannot process
the request<br>", sp);
      return;
    }
    
    // Authenticate the user who want to bid
    sess = getSession();
    Auth auth = new Auth(sess, sp);
    user = auth.authenticate(nick, pass);
    if (user == null)
    {
      printError(" You don't have an account on RUBiS!<br>You have to
register first.<br>", sp);
      releaseSession(sess);
      return;
    }
    
    // Try to find the Item corresponding to the Item ID
    Integer itemId = new Integer(itemStr);
    
    try
    {
      item = (Item) sess.get(Item.class, itemId);
    }
    catch (HibernateException he)
    {
      printError("Failed to execute Query for item: " + he, sp);
      releaseSession(sess);
      return;
    }
    if (item == null)
    {
      printError("<h2>This item does not exist!</h2>", sp);
      releaseSession(sess);
      return;
    }
    
    try
    {
      Query q = sess.createFilter(item.getBids(), "select max(this.bid)");
      List lst = q.list();
      Iterator it = lst.iterator();
      
      // Get the current price (max bid)
      if (it.hasNext())
        maxBid = (Float) it.next();
      else
        maxBid = item.getInitialPrice();
    }
    catch (HibernateException he)
    {
      printError("Failed to executeQuery for max bid: " + he, sp);
      releaseSession(sess);
      return;
    }
    
    try
    {
      Query q = sess.createFilter(item.getBids(), "select count(*)");
      List lst = q.list();
      Iterator it = lst.iterator();
      
      if (it.hasNext())
        nbOfBids = (Integer) it.next();
    }
    catch (HibernateException he)
    {
      printError("Failed to executeQuery for number of bids: " + he, sp);
      releaseSession(sess);
      return;
    }
    
    sp.printItemDescription(item, maxBid, nbOfBids, user, sess);
    
    releaseSession(sess);
    
    sp.printHTMLfooter();
  }
--------------------
Thank you in advance for your help and attention
Arash
-- 
View this message in context: http://www.nabble.com/NullPointerException-error-tp25631989p25631989.html
Sent from the java.net - glassfish users mailing list archive at Nabble.com.