Our MySQL database has a null (long type) column (called referral). We use sleep mode for ORM.
I am trying to get the column value for a given member. Some of them are NULL, and if not, then its identifier points to another member, which is the referee.
The problem is the java code, which I am trying to determine if this member column is null, if not, to do something.
String referrerAffiliateId = Long.toString(member.getReferral());
if (referrerAffiliateId != null){
}
member.getReferral () returns the value (long type) of the referral column. Some of these columns are null and some are not.
The above code compiles fine, but I get a nullPointerException when I call a method on a user whose referral column is null.
How to properly perform detection on this?
Thanks in advance!
Full answer:
Thanks @Marcelo for the best correct answer.
Here is the code in its final state:
Long referrerAffiliateId = member.getReferral();
if (referrerAffiliateId != null) {
}
source
share