I'm trying to get a rudimentory particel engine built for y game project.

I have a number of different classes that all eventualy add their particle effect to a publicaly available ArrayList (the global effect list) in my Game class that stores them for rendering and update.

There are a few times that for some reason I cant explain, where I get a NullPointerExeption when adding to this list, even after it has already been sucsessfully accessed, written to and read from with no problem.

The error apears to be happening only when my ParticleEmitterComponent trys to add its effect to the global effect list, at which point the NullPointerException occours. I think this means that the list itself is equle to null - but I'm not sure if that is what this error means.

If anyone can help or explain to me exactly what this error means, it would be much apreceated.

Exception in thread "main" java.lang.NullPointerException at SpaceLib.Components.ParticleEmitterComponent.<init>(ParticleEmitterComponent.java:32) at SpaceLib.Objects.Projectile.<init>(Projectile.java:38) at SpaceLib.Components.WeaponComponent.initProjectile(WeaponComponent.java:102) at SpaceLib.Components.WeaponComponent.<init>(WeaponComponent.java:48) at SpaceLib.Ship.Ship.<init>(Ship.java:42) at GameLib.DRGame.Load(DRGame.java:130) at GameLib.DRGame.<init>(DRGame.java:105) at isogameengine_01.Main.main(Main.java:21)[/code]

I'm afraid that its all rather hacked together and got really messed up yesterday as I was trying random crap to try fix it. I think I need to have a good clean-up of the code I have before going any further.

This looks like a threading problem to me. The whole of Awt and Swing are not threadsafe and are fullof problems like this, even without the your extensions. There are always several threads actively traversing the window hierarchy; you have (at least) to be very careful; but a better design is to minimizeyour exposure by not making actively changing components part of the window hierarchy.

Yes, and this is very very important to know. The compiler is telling you that you had a null pointer exception exactly where it happened (in ParticleEmitterComponent on line 32). Find that line of code, then find which object being referenced is null, and you know the problem.

If the line of code is as simple as this:

1

Stringoutput = object.toString();

then you would know that object would have to be null, because it's the only reference happening on that line.

If it is more complicated, like this:

1

Stringoutput = object.getProperty().getComponent().toString();

then you know that either object is null, or its property is null, or its property's component is null. Obviously this case is more complicated, so to solve it you would split that line up like Bleb mentioned:

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org