I've made a particle class that creates a particle of Slick2d library, but the XML file doesn't want to load , it keeps giving me null error. I gave it the path as I do for everything but it refuses to work and its been like this for days I just cant get it to open that XML file. If anyone can help me it would be much appreciated.

try {
        particleImage = new Image("res/particles/particle.png", false);
        system = new ParticleSystem(particleImage,1500);

        //load the xml file and add the emitter to the system
        File xmlFile = new File("res/particles/bloodDown.xml");
        ConfigurableEmitter emitter = ParticleIO.loadEmitter(xmlFile);
        emitter.setPosition(315, 358);
    } catch (Exception e) {
        System.out.println("Exception: " +e.getMessage());

Entire particle class : http://pastebin.com/rBR0xpE7

Particle manager class : http://pastebin.com/N8gNFk6W

Slick 2d documentation : http://www.slick2d.org/javadoc/

My structure of workspace:


  • 2
    \$\begingroup\$ Have you stepped through your code to identify exactly where the problem is? If the xml file is loading properly, but the returned emitter is null, then chances are there is a formatting issue with the xml file. If the xml file just never loads, then consider investigating a pathing issue. \$\endgroup\$ – Evan Apr 21 '13 at 5:17
  • \$\begingroup\$ Its the path issue, I print out the path it looks fine like for everything else, its just that ConfigurableEmitter emitter = ParticleIO.loadEmitter(xmlFile); doesnt load it. \$\endgroup\$ – Matthew Apr 21 '13 at 6:14
  • \$\begingroup\$ Printed out the path? I assume you know how to use breakpoints for debugging correct? Well, assuming that your File is being constructed properly(that the XML file is actually found), then the xml format may be incorrect. \$\endgroup\$ – Evan Apr 21 '13 at 14:39
  • \$\begingroup\$ Well it does print out the name of the xml file that is stored inside the xml. But there is still ERROR:null java.lang.NullPointerException at javagame.ParticleManager.update(ParticleManager.java:25) , i checked 10 times with debugging and i still dont know what is wrong with it \$\endgroup\$ – Matthew Apr 21 '13 at 15:22
  • \$\begingroup\$ Well what line specifically is it giving you the NRE on? That will give you a hint as to what's wrong. \$\endgroup\$ – Tetrad Apr 22 '13 at 3:22

You don't need to create a symbolic Java File to pass to the ParticleIO method, you can just provide the relative String reference to the path of the XML. ParticleIO is a class used for Serializing and Deserializing ConfigurableEmitters through XML. So if you are trying to "load" an XML using ParticleIO, then you are trying to deserialize that XML into a ConfigurableEmitter. For this to work properly it must have been serialized to that XML file first. If loadEmitter() is returning null and your path is 100% correct, then you are trying to deserialize an incorrect XML file.

  • \$\begingroup\$ I tried passing it string only this is what i get Sun Apr 21 17:13:49 CEST 2013 ERROR:null java.lang.NullPointerException at javagame.ParticleManager.update(ParticleManager.java:25) i added particleManager code in the question too. \$\endgroup\$ – Matthew Apr 21 '13 at 15:14
  • \$\begingroup\$ Again if the path is correct and it is returning null, then you are trying to deserialize something that wasn't properly serialized. \$\endgroup\$ – Fizzik Apr 22 '13 at 12:20

Not the answer you're looking for? Browse other questions tagged or ask your own question.