CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2009
    Posts
    105

    Why is this coming up with a NullPointerException Error

    Hello, i'm working with SQL's and in this bit of code i'm basically trying to fetch the data located in the 'date' column in my table.

    Code:
                    Statement pStmt = null;
    		pStmt.executeUpdate("SELECT date FROM " + ticker);
    		RS = pStmt.getResultSet();
    		ArrayList<Date> dates = new ArrayList<Date>();
    		while(RS.next())
    		{
    			if(RS.wasNull())
    				System.out.println("Null");
    			else
    				System.out.println("Not Null");
    			System.out.println(RS.getDate(1));
    			dates.add(RS.getDate(1));
    		}
    However the error i am getting is this:

    Code:
    Exception in thread "main" java.lang.NullPointerException
    	at Main.Database.getDateData(Database.java:193)
    	at Main.Main.main(Main.java:23)
    The line the nullPointer is coming up at is in red.

    I have tried using both executeQuery and executeUpdate.

    Thanks

    -Alex

  2. #2
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    Re: Why is this coming up with a NullPointerException Error

    pStmt is null - you are setting it to null on the line above.
    You need to create a Statement object and assign it to pStmt.
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

  3. #3
    Join Date
    Jan 2011
    Posts
    24

    Re: Why is this coming up with a NullPointerException Error

    This is the most obvious I have seen must be true beginner. Anyway when you get NullPointerException than look at the line and see if any object on which you are calling method, variable or doing synchronization is null , that would be the reason.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured