This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JDBC and the fly likes Another infamous NullPointerException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Another infamous NullPointerException" Watch "Another infamous NullPointerException" New topic
Author

Another infamous NullPointerException

Brian LaRue
Ranch Hand

Joined: Feb 01, 2006
Posts: 45
I'm running Netbeans 6.7.1 and am on Ubuntu 9.10. I'm attempting to author my first swing app which displays a form, takes the information, and then writes it to a database (OpenOffice.org Base). I'm a n00b so bear with me, please.

Here's the error message i get at runtime:


Looks like it's complaining about my executeUpdate method. Here's that code:



I know that there's probably better way(s) to do the above, I guess I'm open for suggestions there as well. This is probably the 4th or 5th revision that I've tried and all are unsuccessful . Where/Why am I getting a NullPointerException?

Background info:

Database Name: Test ( /home/brian/Documents/BaseConnection/Test.odb)
Table Name: Contacts

Any help is appreciated!
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Yup, line 28. If your line numbers in your post match the line numbers in your actual code, then that's this line:

If you're getting a NPE there, it can only be because the "state" variable is null. Look through the code and try to convince me that it can be anything but null... you won't be able to do it.
Brian LaRue
Ranch Hand

Joined: Feb 01, 2006
Posts: 45
Yeah, my state variable is initialized to null and not used until this executeUpdate() statement. Hmm...lemme take that initialization (to null) out and give it another go.

Edit: That's not it. I changed Statement state = null; (line 8 above) to Statement state; ran the program again and same result: NPE... any other ideas?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Another infamous NullPointerException
 
Similar Threads
Desktop.Action.EMAIL
error handling
How to convert arabic numbers received from JTextField to a Double?
Help with getting the database to take values (Java-MySQL)
nullPointerException on entity manager methods