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

  • Home
  • SEARCH
  • 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 6202965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:49:52+00:00 2026-05-24T04:49:52+00:00

I’m currently learning game programming using a framework called libgdx. It allows users to

  • 0

I’m currently learning game programming using a framework called libgdx. It allows users to make programs that can easily run on both a Java virtual machine on the desktop and an Android mobile phone. I am trying to make a basic program that will display a character on screen and allow me to move it back and forth with the keyboard. I have created 3 classes – one called Assets, which loads files into the memory and converts them into Textures and Animations, one called InputHandler, which responds to key input by changing animations, direction of movement etc., and one called FightView, which is essentially where all the rendering gets done. The InputHandler is called from the FightView class with the typical command input = new InputHandler(anim, frame);. The constructor for InputHandler looks like this:

public InputHandler(Animation animation, TextureRegion region){

    Assets.load();  //loads textures from files into memory and creates animations from them
    animation = Assets.playStance;  //set initial animation to be used
    region = animation.getKeyFrame(0, true);    //make TextureRegion equal to first frame in animation

}

Now, what I want to happen is simply that the Animation and TextureRegion passed into the constructor are set to the values quoted above, so that, for example, if I was to mention region in the FightView class after input had been declared, it would be set as animation.getKeyFrame(0, true);. From my limited experience of Java this is what I believe should happen, but I get a NullPointerException at compile time pointing to the second line in the code below:

    input = new InputHandler(anim, frame);
    x = centreX - (frame.getRegionWidth() / 2);

Clearly, frame is still null, even after being passed through the constructor, which (as can be see in the third line in the constructor) should assign to it a value. Note that before being passed into the constructor they both are actually null – I am trying to create a class that will give the fields data without needing to do so in the FightView class.

Any help appreciated. This could be the wrong way to go about this – what I am trying to do is create an object that, upon initialisation, will load the Animation and TextureRegions with data.

  • 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-24T04:49:54+00:00Added an answer on May 24, 2026 at 4:49 am

    The problem you are having is due to a misunderstanding of a basic Java concept. Java passes parameters by value, not reference. What you have written will never work as you expect.

    First, I recommend you perhaps tackle a simpler problem or take a side trip to reinforce some of the basic Java concepts and object concepts.

    Second, here’s a brief answer to achieve what you desire.

    Add members to the InputHandler class to hold an Animation and a TextureRegion. In the constructor (which would take no parameters) you would assign the values like you have done except you would assign them to the member variables.

    class InputHandler {
    
        public Animation animation;
        public TextureRegion region;
    
        public InputHandler() {
    
            Assets.load();  //loads textures from files into memory and creates animations from them
            animation = Assets.playStance;  //set initial animation to be used
            region = animation.getKeyFrame(0, true);    //make TextureRegion equal to first frame in animation
    
        }
    }
    

    After constructing the InputHandler you could reference it’s members (frame in this case) and see your correct values.

    input = new InputHandler();
    x = centreX - (input.frame.getRegionWidth() / 2);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am currently running into a problem where an element is coming back from
I want use html5's new tag to play a wav file (currently only supported
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have a JSP page retrieving data and when single or double quotes are
Seemingly simple, but I cannot find anything relevant on the web. What is the
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.