Example. NullPointerException

[comp1110-92]

If you try to access a field or method of a null value, Java will raise a NullPointerException:

void main() { String s = null; int l = s.length(); }

This program crashes:

Exception in thread "main" java.lang.NullPointerException: Cannot invoke "String.length()" because "<local1>" is null at test.main(test.java:3)
bars magnifying-glass caret-down plus minus arrow-right xmark