Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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);
        system.addEmitter(emitter);
    } catch (Exception e) {
        System.out.println("Exception: " +e.getMessage());
        e.printStackTrace();
        System.exit(0);
    }

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:

structure

share|improve this question

closed as too localized by bummzack, Anko, Byte56, Josh Petrie, ClassicThunder Apr 25 '13 at 15:44

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

2  
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. –  Evan Apr 21 '13 at 5:17
    
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. –  Matthew Apr 21 '13 at 6:14
    
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. –  Evan Apr 21 '13 at 14:39
    
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 –  Matthew Apr 21 '13 at 15:22
    
Well what line specifically is it giving you the NRE on? That will give you a hint as to what's wrong. –  Tetrad Apr 22 '13 at 3:22

1 Answer 1

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.

share|improve this answer
    
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. –  Matthew Apr 21 '13 at 15:14
    
Again if the path is correct and it is returning null, then you are trying to deserialize something that wasn't properly serialized. –  Fizzik Apr 22 '13 at 12:20

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