Ask your own question, for FREE!
Computer Science 17 Online
OpenStudy (anonymous):

I'm getting the error java.lang.NullPointerException even though I'm not using null in my code. Can you tell me why and how I can fix it?

OpenStudy (rsmith6559):

Not with the information provided. Sorry.

OpenStudy (blurbendy):

Maybe you haven't initialized some value?

OpenStudy (e.mccormick):

This is a rough example of what can cause that error: Lets say I have MainProgram.java and Data.java. In MainProgram.java I have: ``` ArrayList<Data> data; ``` So that `data` can be used as an array list of Data.java defined objects. Then I go on my merry way and use it: ``` data.add(new Data(1,2)); ``` This will generate a null pointer error. That first thing above is a declaration of what type `data` is. If I forget to do something like `data = new ArrayList<Data>` to initialize it in there, then I can't use it. You probably have some situation like that going on, which is what blurbendy is talking about.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!