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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:48:00+00:00 2026-06-03T14:48:00+00:00

In the grid world case study foe my final project I am making a

  • 0

In the grid world case study foe my final project I am making a game. In the game if the player clicks the “W” key the shiftUp() method is called which makes all of the other actors of a certain instance move down to create the illusion of the player moving. This isn’t a finished implementation of the method but this should get all the actors in the grid and test if they are an instance of a class called Enemy which extends Actor. If so the actor should move up one space. When I call this method a NullPointerException is called on the line that calls enemy.moveTo(…); This shouldn’t happen because I check to see if it’s null. Can anyone help me with this? I get this:
Exception in thread “AWT-EventQueue-0” java.lang.NullPointerException

public void shiftUp()
{
    if (((GameGrid)getGrid()).getMinX() != 0)
    {
        Grid<Actor> grid = getGrid();
        if (grid != null)
        {
            for (int y = 0; y < getGrid().getNumRows(); y++)
                for (int x = 0; x < getGrid().getNumCols(); x++)
                {
                    Actor enemy = grid.get(new Location(y,x));
                    if (enemy != null && enemy instanceof Enemy)
                        enemy.moveTo(new Location(enemy.getLocation().getRow() - 1, enemy.getLocation().getCol()));
                }
        }
    }
}
  • 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-03T14:48:02+00:00Added an answer on June 3, 2026 at 2:48 pm

    Since you are checking for enemy != null beforehand, I’m guessing that enemy.getLocation() is returning null, which is causing a NullPointerException when you call null.getRow() and null.getCol().

    If this is the case, then it looks like the problem is that your Actor is never given a proper Location in the grid. Make sure you are using the putSelfInGrid(Grid<Actor> grid, Location loc) method to place the Actor in the grid (not grid.put(Location loc, E obj)), as putSelfInGrid() sets your Actor‘s location accordingly.

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

Sidebar

Related Questions

This is my 960 grid system case: <div class="kundregister_grid_full"> <div class="kundregister_grid_1">ID</div> <div class="kundregister_grid_1">Namn</div> <div
(GridWorld as in Collegeboard's AP exam case study thing) So, I've been working on
I am trying to do an assignment using Gridworld, a case study put out
My use case is to log millions of messages into a customizable grid GUI
I would like to make a ListBox function like a Grid . Each time
I'm trying to figure out why I would use a grid system. I have
grid = [ ['x'] * w ] * h grid[0[2]] = 'a' This was
What grid library does swivel.com use? It looks pretty nice. Is it made inhouse?
We're using Infragistics grid (most probably, we'll have 8.2 version at the end) and
I'm building a grid in ASP.NET MVC and I have the following issue: Above

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.