Jump to content

lingmaaki

Members
  • Posts

    2
  • Joined

  • Last visited

  • Feedback

    0%

Posts posted by lingmaaki

  1. On 10/22/2017 at 5:01 AM, HeyImJamie said:

    NullPointerExceptions are exceptions that occur when you try to use a reference that points to no location in memory (null) as though it were referencing an object. Calling a method on a null reference or trying to access a field of a null reference will trigger a NullPointerException. 

    For example,

    String s = null;
    int len = s.length();  // NullPointerException because s is null

    So you should check if the variable is null before calling any method on it, for example:

    int len;
    if (s == null) {
        len = 0;
    }
    else {
        len = s.length();  // safe, s is never null when you get here
    }

     

×
×
  • Create New...