Array of Node result in Pointer Null Exception

Hello, i’m actually working on jme3 and it’s my first project on this framework but don’t really care :wink:

I have a problem because in order to move batched geometries separetely from each other i have to attach a control per Node so i decide to make an array of Node.
My problem is that when i want to attach some control to my array of node easy as :

face_front[b].addControl(myControl);

It result in a null pointer exception.

I try different things as checking my “counter” b (even if it will be because of that it would be and array bound of exception) but nothing change.
So i try to attach my control to a single node not in an array and it work well so i conclude that’s a problem with node array.

If anyone have an idea it will help me a lot because declaring 60 Nodes one by one is pretty dirty and would like to avoid it :slight_smile:

How do you add the nodes to the array?

i declare first my arrays like that :

private Node[] face_front = new Node[16];

And then i attach my control as i said before

If you don’t post the stack trace to an exception then don’t even both mentioning it at all. It is just as useful unmentioned as it is without the stack trace.

Do note, though: a single control instance can only be attached to one spatial at a time.

@mantisis said: i declare first my arrays like that :

private Node[] face_front = new Node[16];

And then i attach my control as i said before

So, you don’t even set the nodes first? ie: face_front[b] = new Node()

Trying to learn Java at the same time as learning 3D programming is like trying to learn to ride a bike while also trying to learn to shave with a straight razor. Better done separately.

1 Like

You know you just created an empty array of references to objects of type node?

you need to do array[X] = new Node();
to actually have a node in it.

1 Like
@pspeed said: Trying to learn Java at the same time as learning 3D programming is like trying to learn to ride a bike while also trying to learn to shave with a straight razor. Better done separately.

We should open a wiki page featuring the best quotes

1 Like
@pspeed said: So, you don't even set the nodes first? ie: face_front[b] = new Node()

Trying to learn Java at the same time as learning 3D programming is like trying to learn to ride a bike while also trying to learn to shave with a straight razor. Better done separately.

Thanks for your remark that’s really constructive.
Excepting that i’m not really learning java, that’s not my first java app but with this kind of remark i don’t think you know the fact that when you are writing so many lines, one stupid things like this could turn you crazy because you are sure to have done the right thing so you ask a friend with a new eye and he find that stupid error. But you are probable a kind of programmer which never do error because he’s tired.

Well i will don’t really pay much longer attention to that and i will even thank you for your help despite of your condescencion.

Don’t get this wrong, in 99/100 cases it is usually people with no java knowledge, instead of smaller errors.
So this is the default answer being given.

Oh okay i understand, but i’m not really used to this “judgy” atmospheres furthermore for a stupid mistake like this i’m just enough pissed against me :slight_smile:

@mantisis said: Oh okay i understand, but i'm not really used to this "judgy" atmospheres furthermore for a stupid mistake like this i'm just enough pissed against me :)

As you said, maybe you were tired. Maybe wait until you look upon code with fresh and rested eyes before posting.

I’m not trying to be judgmental. It sounds harsh when I tell people they should learn Java better but really I’m trying to prevent them from getting needlessly discouraged. There are a hundred easier ways to start development.

For the record, all of the evidence was there even if it was caused by sleepiness:
-no importance given to the reporting of the exception (a big beginner mistake)
-inability to instantly judge the cause of a NullPointerException (almost without fail a beginner mistake since these are the single easiest exception to deal with)
-not automatically thinking to allocate the members of the array
-not thinking to do 20 seconds of debugging before writing a long forum post that clearly took more than the time it would have taken to debug.

Hopefully, if you (as a Java developer with more experience than we thought) look at that evidence you will see why it was easy to think you might be new to Java. I meant no offense.