Null Pointer Exception

ankur tyagi

Ranch Hand

Posts: 49

posted 6 years ago

Hello friends ,
I am trying to develop a web app that will show flight timings of different airports...
but i am having the following error when running servlet...
the interface is basic from beer application in headfirst but i was trying a test run
type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

some where object is not initialized.
best way is to run un debug mode or print incremental integers in the doubted line..by that you will get to know where exactly your code got struck.

SudheerSCWCD, SCJP 5

ankur tyagi

Ranch Hand

Posts: 49

posted 6 years ago

the problem is that nothing is being added to the ArrayList..
is there any problem with the logic??
the servlet creates an object of class AirportDD , having a varaible of type List code.
the function is called and the function instantiates code as an arraylist and adds some string to it...
will the servlet have the same list as the attribute of the object it created ???
can any one help....

If the NPE is being thrown on a line that contains only a rs.next() statement, then the problem isn't that the resultSet is returning nothing.
It's that the resultSet variable "rs" is null.

This means that your problem is happening before you get to that line.

You've got print statements in all of your catch blocks.
I suggest you clear all of your logs, run it again until it breaks and go through them to see what else is being thrown before you try to call rs.next().
If I had to take a wild guess it would be that the app can't find your JDBC driver.
You might want to do something more in your catch block than just log errors.
If you can't make the database call, your app should be dying before you try to read from the resultSet.

the initial problem was removed by making a system DSN.
the servlet is getting values ..and page is generated.
but there is a new sort of problem now..
when i start the database and the tomcat and load the page , the values are shown just fine but if i refresh the page 4-5 times
the servlet starts giving the same exception all over again..
i suspect its because not clossing connections as mentioned by Ben

can someone suggest me how to close connection in respect to the code AirportDD.java
as i am using different functions...