Posts

Showing posts with the label java

What is a NullPointerException, and how do I fix it?

What is a NullPointerException, and how do I fix it? What are Null Pointer Exceptions ( java.lang.NullPointerException ) and what causes them? java.lang.NullPointerException What methods/tools can be used to determine the cause so that you stop the exception from causing the program to terminate prematurely? This question's answers are a collaborative effort: if you see something that can be improved, just edit the answer to improve it! No additional answers can be added here 12 Answers 12 When you declare a reference variable (i.e. an object) you are really creating a pointer to an object. Consider the following code where you declare a variable of primitive type int : int int x; x = 10; In this example, the variable x is an int and Java will initialize it to 0 for you. When you assign it to 10 in the second line your value 10 is written into the memory location pointed to by x. int But, when ...