0

How to solve java.lang.NullPointerException.

this exception is throw in array initialization.

13th Aug 2017, 7:30 AM
Shivam Jamaiwar
Shivam Jamaiwar - avatar
2 Answers
0
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 } http://net-informations.com/java/cjava/null.htm
20th Sep 2019, 4:42 AM
rahul kumar
rahul kumar - avatar