Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2008
    Location
    Gloucester
    Posts
    976
    Tokens
    0

    Default Java Null Pointer headache

    Hey hey hey,

    First off, full disclosure. This is a side project which broke off from an assignment for Uni, part of the code in question is going to be used in an assignment and therefore I won't be able to post much of it in case it shows up on google and I'm though to have plagiarised it. And of course this means I'll be unable to use any code you directly write, therefore textual help > code.

    On to the meat and veg. Most of the program uses the becker robots package (the assignment is to program a robot that can escape any maze it's put in). The side project I came up with is a method that scans in a .lozmap file which contains all the information required to construct the maze and place the robot (see pic).



    It loads up the map fine, however once the map is loaded I get a wonderful NullPointer in main line 14, which is:

    Code:
    A1.makeAMove(myRobot);
    and in A1, line 190 which is:

    Code:
    if(myRobot.frontIsClear())
    A1 being the class containing the method which escapes the maze, and makeAMove being the method in said class.

    Obviously then the problem is with myRobot. I'm certain I've declared it correctly:

    Code:
    public static Robot myRobot;
    And it doesn't seem to matter where I put it, the end result is the same. I've tried in A1, the main and in my map reader class (LozTools) to no avail. I've also made sure that the Robot is declared before any use of myRobot.

    I'm running out of ideas, +rep to anyone who can come up with something to help





  2. #2
    Join Date
    Jun 2005
    Posts
    4,795
    Tokens
    0

    Latest Awards:

    Default

    Have you actually created a new instance of "Robot"? From the code you've just declared that myRobot can be of type Robot but not actually set it to be a instance of Robot hence it is null.

  3. #3
    Join Date
    Jul 2008
    Location
    Gloucester
    Posts
    976
    Tokens
    0

    Default

    Aye I had. I managed to fix the problem at uni. I blame tiredness, I never thought I'd do something as stupid as this:

    Line 112:
    Code:
    public static Robot myRobot;
    Line 159:
    Code:
    Robot myRobot = new Robot(myCity, variableArray2[3], variableArray2[2], robotDirectionImp);
    I oooonce was bliiiind but now am found. Ta for the respond bro, +rep

    Edit: need to spread





Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •