Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds


  Asked By: Rena    Date: Oct 16    Category: Java    Views: 1728

I keep getting a java.lang.NullPointerException
when I execute my program.

at Set.main(Set.java:15)

can anyone tell me how to read this line and what it means?
I've been interpriting it as the error resides on line 15 but does
the numbering start on line 0 or 1. If I'm wrong what does it

line 15 is


where size is int size

public void createSet(int size){
length = size;



7 Answers Found

Answer #1    Answered By: Douglas Sullivan     Answered On: Oct 16

The entire piece of code would make it easier. However I am willing to
jump off the cliff and suggest that for some reason size  isn't
constructed properly. Like maybe for some reason it is equal to null;

Answer #2    Answered By: Cambria Lopez     Answered On: Oct 16

probably more like setA hasn't been initialised yet, but the code would be good

Answer #3    Answered By: Topaz Ramirez     Answered On: Oct 16

Let's say that the code snippet (we don't have the
entire code) is implementing the actionLister, then
you have to have a method called actionPerformed,
let's say that it's the one that throws the
nullPointerException (if it is) then add to that line
"throws nullPointerException", then put your code in
the try braces in the catch-try statement, then you
will run the program  without problems. Check the SDK
for the exact syntax. A nullPointerException is, just
my guess, the most common "error" in Java, probably
because of you don't access pointers the way you do in
C and C++.

Answer #4    Answered By: Angie Bennett     Answered On: Oct 16

What is the length. Is it a int  or a object.
Null Pointer Exception usually throws when u r trying something to assign to
a object when the memory for that object is not allocated.

Answer #5    Answered By: Ray Lawrence     Answered On: Oct 16

the variable 'setA' is null...............

Answer #6    Answered By: Chad Bradley     Answered On: Oct 16

Thanks for the help I was able to get the problem
solved through the Java Beginners Club. It turns
out that I hadn't instantiated(spelling) the array
element. Thats all. I guess its a common error
for people starting out.

Answer #7    Answered By: Laurel Collins     Answered On: Oct 16

I think you don't instance the setA object. The secuence is:

- Declare: Objectxxx setA;
- Instance: setA = new Objectxxx();
- Use: setA.createSet(size);

Didn't find what you were looking for? Find more on java.lang.NullPointerException Or get search suggestion and latest updates.