CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 3 of 3

Thread: java.lang.NullPointerException

  1. #1
    Join Date
    Feb 2012


    I would be very gratefull if you could find where is my problem and how can I fix it. (java.lang.NullPointerException)

    From a html page I get a textfield and I upload 2 files. In the servlet I save the uploaded files into a specific folder and after that I am connecting to a database where I want to store the string got from html and the file paths from the uploaded files

    I am sure that the error is somewhere in the code I copy-paste it here.

    String idmarca = request.getParameter("rid");

    String itemName1 = fi.getName();
    String path1 = new String("C:\\UploadedFiles\\" + itemName1.substring(itemName1.lastIndexOf("\\")));

    String itemName2 = fi2.getName();
    String path2 = new String("C:\\UploadedFiles\\" + itemName2.substring(itemName2.lastIndexOf("\\")));
    Connection con = null;
    PreparedStatement ps;

    String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
    String db = "jdbcdbc:upload";
    con = DriverManager.getConnection(db, "", "");
    String sql = "INSERT INTO file1(marca,file1,file2) VALUES(?, ?, ?)";
    ps = con.prepareStatement(sql);

    ps.setString(1, idmarca);
    ps.setString(2, path1);
    ps.setString(3, path2);
    int s = ps.executeUpdate();
    System.out.println("Uploaded successfully !");

    catch(Exception e){
    finally {
    // close all the connections.

    at UploadServlet.doPost(
    at javax.servlet.http.HttpServlet.service(
    at javax.servlet.http.HttpServlet.service(
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(
    at org.apache.catalina.core.StandardWrapperValve.invoke(
    at org.apache.catalina.core.StandardContextValve.invoke(
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(
    at org.apache.catalina.core.StandardHostValve.invoke(
    at org.apache.catalina.valves.ErrorReportValve.invoke(
    at org.apache.catalina.valves.AccessLogValve.invoke(
    at org.apache.catalina.core.StandardEngineValve.invoke(
    at org.apache.catalina.connector.CoyoteAdapter.service(
    at org.apache.coyote.http11.AbstractHttp11Processor.process(
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(
    at java.util.concurrent.ThreadPoolExecutor$

    Thank you in advance

  2. #2
    Join Date
    Feb 2012

    Re: java.lang.NullPointerException

    Problem solved! I had to use null check to the variables before using them to store in database.

  3. #3
    Join Date
    Jan 2011

    Re: java.lang.NullPointerException

    Glad to hear that. As a general rule I will look on the line where its coming. e.g.

    at UploadServlet.doPost(

    and any object which is calling method or accessing property must be null on that line than find out why its null before putting null check because sometime problem may be on the source from where its coming.

Tags for this Thread

Posting Permissions

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

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

This is a survey!

HTML5 Development Center