[Solved] Missile don’t fire [closed]


Welcome to Stack Overflow!

Some suggestions for your question – please be sure to clean up the code that you post and only post relevant sections, it’s very hard to read cluttered code like this. And as Marc B said, it’s tough to tell what you’re actually asking, so please be clear in your question and tell us what you’ve already tried.

From what I can tell, you’re having trouble calling the Missilies.fire (sic) method from the keyPressed event handler. Let’s break this down, since you need to do 3 things:

  1. Create the missile. Nothing else will work until you create an instance of the Missilies class. Calling Missilies.fire won’t work because that’s like telling the engineers to fire the missile blueprints rather than actually firing a missile. Missilies newMissile = new Missilies(x,y);
  2. Fire the missile. NOW you can call fire on the instance you’ve created: newMissile.fire(this);
  3. Finally, you can add the missile that you’ve created to your array: missilies.add(newMissile);

Again, it’s really hard to read your code so take my suggestions with a grain of salt. Please do try to clean up the question!

edit: Based on your comment clarification above about the NullPointerException, it’s much clearer what the problem is: you’re not initializing your missilies ArrayList! You should make sure that you initialize every object you have before using it. You need a line like missilies = new ArrayList<Missilies>(); in your public Player (MainClass mc) function. I’m not going to go through all your code, but you should go through and check that you’ve initialized every other object as well.

3

solved Missile don’t fire [closed]