Results 1 to 1 of 1
  1. #1
    trivektor is offline Member
    Join Date
    Sep 2008
    Posts
    6
    Rep Power
    0

    Default NullPointerException caused by FileItem getString() method

    I was writing a code to save and get the content of users uploaded file:

    //Create a factory for disk-based file items
    FileItemFactory factory = new DiskFileItemFactory();

    //Create a new file upload handler
    ServletFileUpload upload = new ServletFileUpload(factory);

    //Parse the request
    List items = upload.parseRequest(arg0);

    //Retreive the file just uploaded
    Iterator itr = items.iterator();
    FileItem item = (FileItem) itr.next();

    File saveTo = new File("E:\\CDLG_Files\\UserUploadedSpreadsheets\\" + System.currentTimeMillis() + ".txt");

    try {
    item.write(saveTo);
    System.out.println("User's spreadsheet saved successfully");
    System.out.println("Processing uploaded data");
    }
    catch (Exception e) {
    System.out.println("Error saving user's uploaded file(s)");
    }

    String output = item.getString();

    and I then when I ran the code, the uploaded file was save fine but I got a null pointer exception at the getString(). I wonder if anyone knows why this exception occurs? Below is the strack trace:

    [11/14/08 9:34:27:120 EST] 00000036 SystemErr R java.lang.NullPointerException
    [11/14/08 9:34:27:120 EST] 00000036 SystemErr R at java.lang.String.<init>(String.java:261)
    [11/14/08 9:34:27:120 EST] 00000036 SystemErr R at org.apache.commons.fileupload.disk.DiskFileItem.ge tString(DiskFileItem.java:350)
    [11/14/08 9:34:27:120 EST] 00000036 SystemErr R at com.ibm.cdlabelgenerator.servlets.CreateMultipleLa bels.processDataUpload(CreateMultipleLabels.java:2 11)
    [11/14/08 9:34:27:120 EST] 00000036 SystemErr R at com.ibm.cdlabelgenerator.servlets.CreateMultipleLa bels.processRequest(CreateMultipleLabels.java:84)
    [11/14/08 9:34:27:120 EST] 00000036 SystemErr R at com.ibm.cdlabelgenerator.servlets.CreateMultipleLa bels.doPost(CreateMultipleLabels.java:52)
    [11/14/08 9:34:27:120 EST] 00000036 SystemErr R at javax.servlet.http.HttpServlet.service(HttpServlet .java:763)
    [11/14/08 9:34:27:120 EST] 00000036 SystemErr R at javax.servlet.http.HttpServlet.service(HttpServlet .java:856)
    [11/14/08 9:34:27:120 EST] 00000036 SystemErr R at com.ibm.ws.webcontainer.servlet.ServletWrapper.ser vice(ServletWrapper.java:989)
    [11/14/08 9:34:27:120 EST] 00000036 SystemErr R at com.ibm.ws.webcontainer.servlet.ServletWrapper.han dleRequest(ServletWrapper.java:501)
    [11/14/08 9:34:27:120 EST] 00000036 SystemErr R at com.ibm.ws.wswebcontainer.servlet.ServletWrapper.h andleRequest(ServletWrapper.java:464)
    [11/14/08 9:34:27:120 EST] 00000036 SystemErr R at com.ibm.ws.webcontainer.servlet.CacheServletWrappe r.handleRequest(CacheServletWrapper.java:90)
    [11/14/08 9:34:27:120 EST] 00000036 SystemErr R at com.ibm.ws.webcontainer.WebContainer.handleRequest (WebContainer.java:744)
    [11/14/08 9:34:27:120 EST] 00000036 SystemErr R at com.ibm.ws.wswebcontainer.WebContainer.handleReque st(WebContainer.java:1433)
    [11/14/08 9:34:27:120 EST] 00000036 SystemErr R at com.ibm.ws.webcontainer.channel.WCChannelLink.read y(WCChannelLink.java:100)
    [11/14/08 9:34:27:120 EST] 00000036 SystemErr R at
    Last edited by trivektor; 11-16-2008 at 05:21 AM.

Similar Threads

  1. Replies: 3
    Last Post: 06-05-2010, 09:05 PM
  2. Replies: 10
    Last Post: 09-18-2008, 10:41 AM
  3. Non-Static method in static context error
    By wizmang in forum New To Java
    Replies: 4
    Last Post: 04-24-2008, 09:51 AM
  4. Replies: 1
    Last Post: 08-07-2007, 06:05 AM
  5. Error: invalid method declaration
    By silvia in forum New To Java
    Replies: 1
    Last Post: 07-27-2007, 01:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •