Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7993701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:55:52+00:00 2026-06-04T13:55:52+00:00

I am making an android game that spawns enemy sprites at a certain interval

  • 0

I am making an android game that spawns enemy sprites at a certain interval at the top of the screen. There are no syntax errors, but when I run the game it crashes because of this function:

public void updateEnemies() {
    if (numEnemiesCreated == numVisibleEnemies) {
        if (timeLastCreatedEnemy + 1000 < System.currentTimeMillis()) {
            timeLastCreatedEnemy = System.currentTimeMillis();
            boolean createdNewEnemy = false;

            for (int i = 0; i < this.numVisibleEnemies; i++) {
                if (createdNewEnemy == false) {
                    if (holderEnemy[i].isDisposed()) {
                        this.generateNewEnemy(i);
                        createdNewEnemy = true;
                    }
                }
            }
        }

        for(int i = 0; i<numVisibleEnemies; i++){
            if(!holderEnemy[i].isDisposed()){
                holderEnemy[i].move();
            }
        }
    } else {
        holderEnemy[numEnemiesCreated] = new Enemy(context, 0, 0);
        numEnemiesCreated++;
    }
}

I have tried everything, I just can’t get it to work! Here is my log cat crash report:

05-25 18:49:13.031: W/dalvikvm(6736): threadid=9: thread exiting with uncaught exception (group=0x40015578)
05-25 18:49:13.035: E/AndroidRuntime(6736): FATAL EXCEPTION: Thread-10
05-25 18:49:13.035: E/AndroidRuntime(6736): java.lang.NullPointerException
05-25 18:49:13.035: E/AndroidRuntime(6736):     at com.jlennon.gametest.EnemySpawn.updateEnemies(EnemySpawn.java:49)
05-25 18:49:13.035: E/AndroidRuntime(6736):     at com.jlennon.gametest.MainGamePanel$AnimationThread.update(MainGamePanel.java:94)
05-25 18:49:13.035: E/AndroidRuntime(6736):     at com.jlennon.gametest.MainGamePanel$AnimationThread.run(MainGamePanel.java:61)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T13:55:54+00:00Added an answer on June 4, 2026 at 1:55 pm

    Since the uncaught exception you’re getting is a NullPointerException, you will need to check that every element inside of holderEnemy is instantiated to its proper type. You can’t dereference null – which is what is given by default in an array.

    To belabor the point a bit, if you take an array of elements such as:

    Enemy[] holderEnemy = new Enemy[1000];
    

    that is not enough to instantiate the array. You will need to loop over the array and create new Enemys for each element. Otherwise, you’ll need to guarantee that, within the bounds of [0, numVisibleEnemies), your array elements are properly instantiated.

    (Note that I’m guessing at the object type, but the principle applies.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am making an android game that should delete some falling images from the
I am making an android game that should display a message that you have
So I'm making an android app that has more than 100 buttons,but you know
I am making game for android using libgdx my requirement is that when character
i am making a game using andengine in android, in this game various sprites(eggs)
I'm making a game for Android and I'm using transparent PNG's. But does the
I'm making a fast-paced realtime Android game, and everything works great, but the first
I built a TicTacToe game for android. And i want that there should be
I am also new to Java and Android Development, been making a simple game
I'm making a Android app that basically plays video from a website on the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.