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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:37:56+00:00 2026-06-14T20:37:56+00:00

I’m currently adding values to a HashMap<String, SpriteSheetAnimation> . I am also adding to

  • 0

I’m currently adding values to a HashMap<String, SpriteSheetAnimation>. I am also adding to the hashmap in the LoadFile method of my input class. When I add to the hashmap, which is part of the class GameObject that a reference is created for in the FileLoader. I alter the hashmap, adding keys and values to it, and everything is okay.

I then proceed to add the GameObject object to an objectManager where I store all of the objects for my game. When I reference the object in the ArrayList, however, the SpriteSheetAnimation value and the key of that value that I added in the file loader are no longer present. If I try to access them from within the FileLoader after adding them they are there though. I am a little confused. Is there possibly a scope issue going on here?

I’ve just realized something that may help you help me..(the System.out.println)

If I run this the component is not there when i try to fetch with the .toString

private void LoadControllableEntity(XMLEventReader eventReader, int x, int y)
{
    entities.ControllableEntity entity = new entities.ControllableEntity(x, y);
    entity.addComponent(new components.InputComponent(entity), "input");
    while(eventReader.hasNext())
    {
        try
        {

            XMLEvent event = eventReader.nextEvent();
            if(event.isEndElement())
            {
                if(event.asEndElement().getName().getLocalPart().equals("ControllableEntity"))
                {
                    break;
                }
            } else if(event.isStartElement())
            {
                String element = (String) event.asStartElement().getName().getLocalPart();
                if(element.equals("renderable"))
                {
                    entity.addComponent(new components.Renderable(entity), "renderer");
                }
                else if(element.equals("animationComponent"))
                {

                    entity.addComponent(getAnimationComponent(entity, event.asStartElement().getAttributes(), eventReader), "animation");

                }
            }
        } catch(XMLStreamException e)
        {
            e.printStackTrace();
        }
        System.out.println(entity.getComponent("animation").toString());
        managers.ObjectManager.getInstance().addObject(entity);

    }

}

When I run this code though.. It can fetch the component fine(notice I’ve changed where I’m trying to get the component at.)

private void LoadControllableEntity(XMLEventReader eventReader, int x, int y)
{
    entities.ControllableEntity entity = new entities.ControllableEntity(x, y);
    entity.addComponent(new components.InputComponent(entity), "input");
    while(eventReader.hasNext())
    {
        try
        {

            XMLEvent event = eventReader.nextEvent();
            if(event.isEndElement())
            {
                if(event.asEndElement().getName().getLocalPart().equals("ControllableEntity"))
                {
                    break;
                }
            } else if(event.isStartElement())
            {
                String element = (String) event.asStartElement().getName().getLocalPart();
                if(element.equals("renderable"))
                {
                    entity.addComponent(new components.Renderable(entity), "renderer");
                }
                else if(element.equals("animationComponent"))
                {

                    entity.addComponent(getAnimationComponent(entity, event.asStartElement().getAttributes(), eventReader), "animation");
                    System.out.println(entity.getComponent("animation").toString());
                }
            }
        } catch(XMLStreamException e)
        {
            e.printStackTrace();
        }

        managers.ObjectManager.getInstance().addObject(entity);

    }

}
  • 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-14T20:37:57+00:00Added an answer on June 14, 2026 at 8:37 pm

    The problem with your first code-snippet is that you retrieve and print the animation entity on every pass through the loop — even before you add that entity — whereas in your second code-snippet you only retrieve and print it immediately after adding the entity, so obviously it doesn’t have that problem.

    I think you want to change this:

            System.out.println(entity.getComponent("animation").toString());
            managers.ObjectManager.getInstance().addObject(entity);
    
        }
    

    to this:

        }
    
        System.out.println(entity.getComponent("animation").toString());
        managers.ObjectManager.getInstance().addObject(entity);
    

    That is, I think you want those last few steps to be performed after the while-loop has completed, rather than doing it at the end of each iteration.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I am currently running into a problem where an element is coming back from
I've got a string that has curly quotes in it. I'd like to replace
Specifically, suppose I start with the string string =hello \'i am \' me And
I want use html5's new tag to play a wav file (currently only supported

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.