how to fix java.lang.nullpointerexception
July 11, 2012 12:11pm CST
i have a create database and i have to connect it from java netbeans to mysql...so the problem is show after all have no error...but when i want to save my data so exit this problem as in this picture...help me please to fix this problem
11 Jul 12
Hello, Null pointer exception occurs when you re trying to access the result set with zero rows. The reason why it shows Null Pointer exception is there is no such results exist. Try to use this code Results results=DataRequest.executeQuery(query); instead of this alone "executeQuery(query);" before doing this work confirm whether you have imported respective java packages. The error itself is easy to explain, but without a context, it's impossible to tell you where it's happening and why. A java.lang.NullPointerException occurs when a java application or Java applet has been badly coded. Typically, the java program (and consequently the programmer) attempted to access the reference or the handle to a object taht did not exist. If you're seeing the exception when using an existing java application what displays, then the application has been badly coded. If you're getting the exception when writing your own code to display, you'll need to give more details including the code snippet that is causing the exception. The wrong n dirty way of quickly solving (or actually suppressing) the exception is to encapsulate the offending code in a try-catch block and handle the catch in some quite, elegant way. The right way of solving the exception is to figure out the line causing the problem, and trace it's source , reason and data. Good Luck!!