What is NullPointerException?

1 answer

Answer

1203752

2026-05-04 20:55

+ Follow

Java
Java

A NullPointerException is an exception thrown by the Java Virtual Machine when you try to access a variable as if it were an object when it is contains null. For example, the following code would throw a NullPointerException:

String s;

if (s.charAt(0) == 'c') // this line throws NullPointerException

return "s[0] is 'c'";

ReportLike(0ShareFavorite

Copyright © 2026 eLLeNow.com All Rights Reserved.