luckydexte
Programmer
Hello everyone,
Do you have to use a try/catch block to check for a null object? I know this is a pretty simple question but it has been bothering me for a while. An example:
I have a class called RoadCond that is a bean. So the following code throws a Null Pointer Exception if I get a nothing returned from the database.
RoadCond rc = rc.getUniqueQuery() // using Hibernate
if (!rc.equals(null) {
....
This throws the null pointer exception. Hibernate will correctly give me a RoadCond object but there is no values of course in the getters and setters. Obviously I can throw it into a try/catch block but I would think there has to be an easier way to check for a null object. Am I correct?
Thanks for any help,
Brandon
Do you have to use a try/catch block to check for a null object? I know this is a pretty simple question but it has been bothering me for a while. An example:
I have a class called RoadCond that is a bean. So the following code throws a Null Pointer Exception if I get a nothing returned from the database.
RoadCond rc = rc.getUniqueQuery() // using Hibernate
if (!rc.equals(null) {
....
This throws the null pointer exception. Hibernate will correctly give me a RoadCond object but there is no values of course in the getters and setters. Obviously I can throw it into a try/catch block but I would think there has to be an easier way to check for a null object. Am I correct?
Thanks for any help,
Brandon