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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:35:52+00:00 2026-06-10T21:35:52+00:00

I am making a game where you shoot down birds. I’ve made an actor

  • 0

I am making a game where you shoot down birds. I’ve made an actor that acts as a Crosshair, following the mouse around.

This is the code which is generating the error (setLocation is line 18):

MouseInfo mouse = Greenfoot.getMouseInfo();
setLocation(mouse.getX(), mouse.getY());

And the error code:

java.lang.NullPointerException
    at Crosshair.act(Crosshair.java:18)
    at greenfoot.core.Simulation.actActor(Simulation.java:565)
    at greenfoot.core.Simulation.runOneLoop(Simulation.java:523)
    at greenfoot.core.Simulation.runContent(Simulation.java:213)
    at greenfoot.core.Simulation.run(Simulation.java:203)
  • 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-10T21:35:54+00:00Added an answer on June 10, 2026 at 9:35 pm

    If you’re having a null pointer exception in the code you wrote then that means that your mouseinfo object is null.

    According to the documentation:

    getMouseInfo

    public static MouseInfo getMouseInfo() Return a mouse info object with
    information about the state of the mouse.

    Returns: The info about the current state of the mouse, or null if the
    mouse cursor is outside the world boundary (unless being dragged).

    Basically this means your mouse if out of boundaries when that method is called.

    In order to help you out more please describe what exactly where you hoping to achieve.

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

Sidebar

Related Questions

I made a sweet system update feature for this game I'm making here is
This is for an HTML5 canvas game that I am making. In the game,
I'm making some game, and I have made it pretty much all, but not
I am making a game that has its own level editor. The editor simply
I have a character in an iPod Touch game I am making that moves
I am making game for android using libgdx my requirement is that when character
I am making a game that has a win state and a lose state.
I'm making a game that involves a 4*4 grid. The user enters letters and
I am making a game that has several classes and each one do some
I am making a shoot them up game on my iPhone (with planes) and

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.