I really don't understand why java.lang.NumberFormatException: Invalid long: "null" happens here.
The problem snippet is like followings.
try {
userid = ((JSONObject) msg.obj).getString("userid");
if (userid.equals("") || userid.isEmpty() || null==userid) {
onClickLogout();
return;
} else {
client.setUserid(Long.parseLong(userid));
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
onClickLogout();
return;
}
the line client.setUserid(Long.parseLong(userid)); gets following exception
java.lang.NumberFormatException: Invalid long: "null"
at java.lang.Long.invalidLong(Long.java:125)
at java.lang.Long.parse(Long.java:362)
at java.lang.Long.parseLong(Long.java:353)
at java.lang.Long.parseLong(Long.java:319)
at client.setUserid(Long.parseLong(userid));
The point is that the null exception occurs even after null and empty check of the userid in the code. What's wrong with me here? please check it out experts!