Q:

Array assignment produces NullPointerException

I am experiencing problems when assigning a value to an array, which is previously declared like so:
Enemy[] enemies = new Enemy[100];

I also have another variable defining the number of enemies spawned:
int numEnemies = 0;

Later, I (attempt to) dynamically assign members of this array to Enemy objects when the screen is touched:
public void spawnEnemy() {
Enemy enemy = new Enemy(...);
... initialise enemy ...
enemies[numEnemies++] = enemy;  // this line causes NPE
}

I have this stack trace:
01-24 02:00:28.509: E/AndroidRuntime(1394): FATAL EXCEPTION: UpdateThread
01-24 02:00:28.509: E/AndroidRuntime(1394): Process: com.example.menutest, PID: 1394
01-24 02:00:28.509: E/AndroidRuntime(1394): java.lang.NullPointerException
01-24 02:00:28.509: E/AndroidRuntime(1394): at com.example.menutest.GameScene.spawnEnemy(GameScene.java:333)
01-24 02:00:28.509: E/AndroidRuntime(1394):     at com.example.menutest.GameScene.initJoints(GameScene.java:325)
01-24 02:00:28.509: E/AndroidRuntime(1394):     at com.example.menutest.GameScene.loadLevel(GameScene.java:189)
01-24 02:00:28.509: E/AndroidRuntime(1394):     at com.example.menutest.GameScene.createScene(GameScene.java:80)
01-24 02:00:28.509: E/AndroidRuntime(1394):     at com.example.menutest.BaseScene.<init>(BaseScene.java:24)
01-24 02:00:28.509: E/AndroidRuntime(1394):     at com.example.menutest.GameScene.<init>(GameScene.java:32)
01-24 02:00:28.509: E/AndroidRuntime(1394):     at com.example.menutest.SceneManager$1.onTimePassed(SceneManager.java:118)
01-24 02:00:28.509: E/AndroidRuntime(1394):     at org.andengine.engine.handler.timer.TimerHandler.onUpdate(TimerHandler.java:94)
01-24 02:00:28.509: E/AndroidRuntime(1394):     at org.andengine.engine.handler.UpdateHandlerList.onUpdate(UpdateHandlerList.java:47)
01-24 02:00:28.509: E/AndroidRuntime(1394):     at org.andengine.engine.Engine.onUpdateUpdateHandlers(Engine.java:618)
01-24 02:00:28.509: E/AndroidRuntime(1394):     at org.andengine.engine.Engine.onUpdate(Engine.java:605)
01-24 02:00:28.509: E/AndroidRuntime(1394):     at org.andengine.engine.Engine.onTickUpdate(Engine.java:568)
01-24 02:00:28.509: E/AndroidRuntime(1394):     at org.andengine.engine.Engine$UpdateThread.run(Engine.java:858)

EDIT:
My app is written in AndEngine, so the CreateScene() method is called from a SceneManager which I am certain works perfectly.
public class GameScene extends BaseScene {

Enemy enemies[] = new Enemy[100];
int numEnemies = 0;

    public void createScene() {
        ResourcesManager.getInstance().setGameScene(this);
        this.setOnSceneTouchListener((IOnSceneTouchListener) ResourcesManager.mBaseGameActivity);
        createBackground();
        createHUD();
        createPhysicsWorld();
                // the above set up scene for later use
        loadLevel(1);
    }

    public void loadLevel(int levelID) {
        initJoints();
    }

    private void initJoints() {
        mPlanet = new Planet(400, 225, ResourcesManager.getInstance().planet, mVertexBufferObjectManager, 500);
        mPlanet.mBody = PhysicsFactory.createBoxBody(mPhysicsWorld, mPlanet, BodyType.StaticBody, FIXTURE_DEF);
        mPlanet.mBody.setUserData(mPlanet);
        this.attachChild(mPlanet);
        mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(mPlanet, mPlanet.mBody, true, true));

        float x1 = 200;
        float y1 = 112;
        mSatellite = SatelliteFactory.createSatellite(SatelliteType.BASIC, x1, y1, mVertexBufferObjectManager, mPlanet);
        this.attachChild(mSatellite);

    spawnEnemy(); // causes exception

    }

    private void spawnEnemy() {
        float y = getRandomY();
        float maxHealth = 100;
        Enemy enemy = new Enemy(0, y, ResourcesManager.getInstance().satellite_no_image, ResourcesManager.mVertexBufferObjectManager, maxHealth);
        enemy.mBody = PhysicsFactory.createBoxBody(mPhysicsWorld, enemy, BodyType.DynamicBody, FIXTURE_DEF);

        this.attachChild(enemy);
        enemy.mBody.setLinearVelocity(new Vector2((mPlanet.getX() - enemy.mBody.getPosition().x) / PhysicsConstants.PIXEL_TO_METER_RATIO_DEFAULT,
                (mPlanet.getY() - enemy.mBody.getPosition().y) / PhysicsConstants.PIXEL_TO_METER_RATIO_DEFAULT));
        enemy.mBody.setLinearVelocity(new Vector2(mPlanet.getX(), mPlanet.getY() - y));
        mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(enemy, enemy.mBody, true, true));

        enemies[numEnemies++] = enemy; // NPE
    }
}

A:

I'll explain what happens:
How do I call an instance method before calling the instance constructor?
class B {
  B() {
    m();
  }
  void m() {
    System.out.println("B.m()");
  }
}
class X extends B {
  int x = 8;
  void m() {
    System.out.println("X.m() x="+x);
  }
}

public class A {
    public static void main(String[] p) {
        X x = new X();
        x.m();
    }
}

Let's run it:
$ javac A.java 

$ java A
X.m() x=0
X.m() x=8

This kind of misbehavior is not possible in C++ where B.m() rather than X.m() would be called from within the base class constructor.
The constructor B() is called automatically before executing any code from the constructor X(), and so the method X.m() is called before any code within the constructor X() receives control.

