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 6861761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:34:35+00:00 2026-05-27T02:34:35+00:00

I am newbie to android game development. I’ve been trying an example of game

  • 0

I am newbie to android game development. I’ve been trying an example of game development but some how unable to understand the cause of null point exception in android.

    public void onLoadResources() {
         this.mBitmapTextureAtlas = new BitmapTextureAtlas(512, 512,
               TextureOptions.BILINEAR_PREMULTIPLYALPHA);
        BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");

        this.mPlayerTextureRegion = BitmapTextureAtlasTextureRegionFactory
                .createFromAsset(this.mBitmapTextureAtlas, this, "Player.png",
                0, 0);
        this.mEngine.getTextureManager().loadTexture(this.mBitmapTextureAtlas);
        final int PlayerX = (int)(mCamera.getWidth() / 2);
        final int PlayerY = (int) ((mCamera.getHeight() - mPlayerTextureRegion
                .getHeight()) / 2);
        this.player = new Sprite(PlayerX, PlayerY, this.mPlayerTextureRegion);
        this.player.setScale(2);
        this.mMainScene.attachChild(this.player);
    }

The last line "this.mMainScene.attachChild(this.player);" is causing null point exception, even though everything is intialized. After commenting this line everything works fine but display is without sprite.

here is the code where mMainScene is intialized

    public Scene onLoadScene() {
        this.mEngine.registerUpdateHandler(new FPSLogger());
        this.mMainScene = new Scene();
        this.mMainScene.setBackground(new ColorBackground(0.09804f, 0.6274f, 0.8784f));
        return mMainScene;
    }
  • 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-05-27T02:34:36+00:00Added an answer on May 27, 2026 at 2:34 am

    You have not initialized mMainScene. You cannot reference (i.e. attach Children / call methods until you’ve defined what mMainScene is.)

    Could you check if mMainScene is null, or move your assignment of mMainScene into onLoadResources()?

    Can you move the mMainScene definition from onLoadScene into onLoadResources?

    public void onLoadResources() {
         this.mBitmapTextureAtlas = new BitmapTextureAtlas(512, 512,
               TextureOptions.BILINEAR_PREMULTIPLYALPHA);
        BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
    
        this.mPlayerTextureRegion = BitmapTextureAtlasTextureRegionFactory
                .createFromAsset(this.mBitmapTextureAtlas, this, "Player.png",
                0, 0);
        this.mEngine.getTextureManager().loadTexture(this.mBitmapTextureAtlas);
        final int PlayerX = (int)(mCamera.getWidth() / 2);
        final int PlayerY = (int) ((mCamera.getHeight() - mPlayerTextureRegion
                .getHeight()) / 2);
        this.player = new Sprite(PlayerX, PlayerY, this.mPlayerTextureRegion);
        this.player.setScale(2);
        this.mMainScene = new Scene();
        this.mMainScene.setBackground(new ColorBackground(0.09804f, 0.6274f, 0.8784f));
        this.mMainScene.attachChild(this.player);
    }
    
    public Scene onLoadScene() {
        return mMainScene;
    }
    

    Edit:

    Based on an example of Snake it appears that you should add children to the scene in the onLoadScene method:

        public Scene onLoadScene() {
            this.mEngine.registerUpdateHandler(new FPSLogger());
    
            this.mScene = new Scene();
            for(int i = 0; i < LAYER_COUNT; i++) {
                this.mScene.attachChild(new Entity());
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am newbie in android application development. I am using the Form Stuff example
I am a newbie to android development. I am trying to create a List
I am total newbie to Android but I have some knowlege of iPhone apps.
Still an Android newbie , but hopefully someone can point me in the right
Extreme Android developer newbie here...well, new to Android development, not development in general. I
I am a newbie to Android and the Eclipse development environment and would like
I am an Android Newbie and I'm developing Go game application for android. I'm
I am a newbie android developer and I am trying to design a simple
Hi am newbie to android development. I had created one application where i need
I am a newbie to android app development. I want to customize my android

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.