Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

Fix NullPointerException

import org.apache.commons.lang3.StringUtils;

public class NullPointerExceptionExample {
    private static void printLength(String str) {
        if (StringUtils.isNotEmpty(str)) {
            System.out.println(str.length());
        } else {
            System.out.println("Empty string");
        }
    }

    public static void main(String args[]) {
        String myString = null;
        printLength(myString);
    }
}
Source by rollbar.com #
 
PREVIOUS NEXT
Tagged: #Fix #NullPointerException
ADD COMMENT
Topic
Name
9+4 =