#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Location
    Woodstock, Ontario
    Posts
    7
    Rep Power
    0

    Code works anywhere else but not on my machine


    I have been working on someone else's program (writing a tutorial) and have successfully installed the program on 4 other computers. But when I install it on mine, it won't run.

    I am running Tomcat, and can access other javascripts in the webapps directory (e.g., admin, webdav) but when I try to run this particular program, I get the following error message:

    StandardWrapperValve[BudgetServlet]: Servlet.service() for servlet BudgetServlet threw exception
    java.lang.NumberFormatException: null
    at java.lang.Integer.parseInt(Integer.java:377)
    at java.lang.Integer.parseInt(Integer.java:458)
    at budget.MARSBudget.doPost(MARSBudget.java:284)
    at budget.MARSBudget.doGet(MARSBudget.java:1019)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
    at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.j ava:643)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.j ava:643)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
    at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2415)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
    at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.j ava:643)
    at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
    at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.j ava:641)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
    at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.j ava:641)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
    at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.j ava:643)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
    at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:594)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.jav a:392)
    at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:565)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:619)
    at java.lang.Thread.run(Thread.java:479)

    As far as I can tell, I have installed the program exactly as I have on the other machines--same files in the same directories. Can someone step me through troubleshooting this error?

    Thanks.
    Dave
  2. #2
  3. No Profile Picture
    Clueless llama
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Feb 2001
    Location
    Lincoln, NE. USA
    Posts
    2,353
    Rep Power
    117
    Post the code for the MARSBudget.java file
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Location
    Woodstock, Ontario
    Posts
    7
    Rep Power
    0

    MARSBudget code


    This is rather longish, and being very new to all this I have probably included more than necessary. If I have missed something you would find helpful, let me know.

    The same code has worked on other machines I have installed this on, and I suspect it is something in the environment causing the problem rather than the code itself.

    Thanks for your help.

    Dave




    package budget;

    import java.util.Vector;
    import java.util.StringTokenizer;
    import java.text.DecimalFormat;
    import java.text.DecimalFormatSymbols;
    import java.text.SimpleDateFormat;
    import java.util.Calendar;
    import java.util.GregorianCalendar;
    import java.text.DateFormat;
    import java.text.ParseException;
    import java.io.IOException;
    import java.io.ByteArrayOutputStream;
    import java.io.FileOutputStream;
    import java.io.File;
    import java.io.FilenameFilter;
    import java.awt.Color;
    import javax.servlet.ServletException;
    import javax.servlet.ServletOutputStream;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import javax.servlet.http.HttpSession;

    import com.lowagie.text.*;
    import com.lowagie.text.pdf.PdfWriter;

    import inventory.*;
    import common.*;

    public final class MARSBudget extends HttpServlet {

    private Budget budgetObj = null;
    private Inventory inventoryObj = null;
    private boolean[][] isAllowed = null;

    public void init()
    throws ServletException{
    budgetObj = BudgetFactory.getInstance();
    inventoryObj = InventoryFactory.getInstance();

    isAllowed = new boolean[7][CONSTANTS.NUM_OF_CONSTANTS];
    for (int i = 0; i < 7; i++){
    for (int j = 0; j < CONSTANTS.NUM_OF_CONSTANTS; j++){
    isAllowed[i][j] = true;
    }
    }
    //project user
    isAllowed[1][CONSTANTS.DISPLAY_BLANK_INSTITUTE] = false;
    isAllowed[1][CONSTANTS.SAVE_NEW_INSTITUTE] = false;
    isAllowed[1][CONSTANTS.EDIT_INSTITUTE] = false;
    isAllowed[1][CONSTANTS.SAVE_UPDATED_INSTITUTE] = false;

    ******* abbreviating code setting up user permissions ************

    isAllowed[5][CONSTANTS.POST_SAVE_NEW_INSTITUTE] = false;

    }

    private boolean isLoggedIn(HttpSession s){
    Account accountObj = (Account)s.getAttribute("user");
    if (accountObj == null || accountObj.userId == null || accountObj.userId.length() == 0){
    return false;
    }
    else{
    return true;
    }
    }

    private int getUserRole(HttpSession s){
    Account accountObj = (Account)s.getAttribute("user");
    if (accountObj == null || accountObj.userId == null || accountObj.userId.length() == 0){
    return Constants.UNKNOWN_USER;
    }
    else{
    return accountObj.role;
    }
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws IOException, ServletException {
    //Setup object session
    HttpSession session = request.getSession(true);

    String actionStr = request.getParameter("action");
    String servlet = request.getServletPath();
    if (actionStr == null || actionStr.length()==0){
    if (isLoggedIn(session)){
    if (servlet.equals("/budget")){
    getServletConfig().getServletContext().getRequestDispatcher("/Template.jsp?action="+ CONSTANTS.DISPLAY_BUDGET_START_PAGE).forward(request, response);
    }
    else{
    getServletConfig().getServletContext().getRequestDispatcher("/ExecutionTemplate.jsp?action="+ CONSTANTS.DISPLAY_EXECUTION_START_PAGE).forward(request, response);
    }
    }
    else{
    request.setAttribute("target", String.valueOf(CONSTANTS.LOGIN));
    if (servlet.equals("/budget")){
    request.setAttribute("targetServlet", "budget");
    getServletConfig().getServletContext().getRequestDispatcher("/Template.jsp?action="+ CONSTANTS.DISPLAY_LOGIN_FORM).forward(request, response);
    }
    else{
    request.setAttribute("targetServlet", "execution");
    getServletConfig().getServletContext().getRequestDispatcher("/ExecutionTemplate.jsp?action="+ CONSTANTS.DISPLAY_LOGIN_FORM).forward(request, response);
    }
    }
    }

    int action = Integer.parseInt(actionStr);

    if (!isLoggedIn(session) && action != CONSTANTS.LOGIN && action != CONSTANTS.LOGOUT){
    request.setAttribute("target", String.valueOf(CONSTANTS.LOGIN));


    ********** snipping rest of doPost code *******

    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws IOException, ServletException {
    doPost(request, response);
    }

    //Login Account
    private void loginAccount(HttpServletRequest request, HttpServletResponse response, HttpSession session, boolean invalidateFirst)
    throws IOException, ServletException{

    if (invalidateFirst){
    session.invalidate();
    }

  6. #4
  7. No Profile Picture
    Clueless llama
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Feb 2001
    Location
    Lincoln, NE. USA
    Posts
    2,353
    Rep Power
    117
    I had a long reply typed out and lost it when I accidentally hit the back button, SO - here is the short version. You are getting a numberformatexception at line 284 of the doPost in this servlet. at budget.MARSBudget.doPost(MARSBudget.java:284)

    The only parseInt I can see is for the action variable. There is no error checking code for this variable, so if the wrong type is sent from the calling page then this is going to happen. This may merely be a symptom of the other page being wrong, but the NumberFormatException should be caught anyway in case this happens again.

    Look into what the action variable really is and why it is that and you should be on your way to figuring out the problem.
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Location
    Woodstock, Ontario
    Posts
    7
    Rep Power
    0
    Thanks, Nemi.

    I'll look into it. The really curious thing for me, though, is why this would happen on my installation and nobody elses. Seems to me that wherever the action parameter is being set is unreachable. I'll continue to explore.

    Dave

IMN logo majestic logo threadwatch logo seochat tools logo