very likely in your main method rect
is null, and you called rect.getName()
, then Bang! NPE.
because in your getRect(int rectId)
method, you handled exception in the method, and then return a rect
, if there is something going wrong or rs.next()
is false, you will return a null rect
object.
what you could consider to do is, either redesign the getRect()
method, let it never return null, E.g if no record found, or exception occured, throw exception(s); or in your main method, check the rect
, make sure it is not null.