Question

IMPORTANT EDIT: I forgot to actually post a large chunk of the code needed to debug this at first. Here are the links:

http://pastebin.com/rxENqzBB

http://pastebin.com/KVXCfys4

http://pastebin.com/Sgv01P8V

http://pastebin.com/mrNVej67

I am currently making a Java application for Android 4.3 using the ADT IDE. The application contains a map of a campus, and outputs directions to the user from the room they are currently in to the room that they wish to go to (both of which having been input by the user). However, I have run into an issue - the following method always returns null, even when it shouldn't:

Coordinates findCoordsWithRoom(String roomName)
{
    //all floors; 0 -> 1
    for (int z = 0; z < map.length; z++)
    {
        //all rows; 0 -> 10
        for (int y = 0; y < map[z].length; y++)
        {
            //all cols; 0 -> 9
            for (int x = 0; x < map[z][y].length; x++)
            {
                if (dne.equals(map[z][y][x])) { continue; } //if this node is a "dne" node, skip it
                //all valid connections out of this node
                for (int c = 0; c < map[z][y][x].dirArr.length; c++)
                {
                    if (!map[z][y][x].dirArr[c].exists) { continue; }
                    //all rooms on this connection
                    for (int r = 0; r < map[z][y][x].dirArr[c].rooms.length; r++)
                    {
                        String thisRoomName = map[z][y][x].dirArr[c].rooms[r].name;
                        //if this room has the right name
                        if (roomName.equals(thisRoomName))
                        {   //found it
                            return map[z][y][x].coords;
                        }
                    }
                }
            }
        }
    }
    //failed to find it
    return null;
}

Even when my debugger tells me that the relevant variables are equal, if(roomName.equals(thisRoomName)) never evaluates to true, as the program never hits the return statement therein.

This is the map variable:

Node[][][] map =
{
    {   //first floor
        //00   01   02   03   04   05   06   07   08   09 <-x/y:
        {dne, dne, dne, dne, dne, cls, dne, dne, dne, dne}, //00
        {dne, dne, dne, dne,  oc,  cl,  cf, dne, dne, dne}, //01
        {dne, dne, dne, dne, dne, dne, dne, dne, dne, dne}, //02
        {dne, dne, dne, dne, og2,  g4,  gc,  g2, gs1, dne}, //03
        {dne, dne, dne, dne, dne, dne, gs2,  g1,  g3, dne}, //04
        {dne, ot3, dne, ot1,  op, dne, og1, gal, dne, dne}, //05
        {dne, ot4, dne, dne, dne, dne,  a2,  a1, dne, dne}, //06
        {dne,  t3, dne, dne, dne, dne, dne,  a3,  as, dne}, //07
        {dne,  t1, tl1, ot2, dne, dne, dne,  a4, dne, dne}, //08
        { ts,  t2, tl2, ot5, dne, dne, dne, dne, dne, dne}, //09
        {dne,  t4, tls, dne, dne, dne, dne, dne, dne, dne}, //10
    },
    {   //second floor
        //00   01   02   03   04   05   06   07   08   09 <-x/y:
        {dne, dne, dne, dne, dne, CLS, dne, dne, dne, dne}, //00
        {dne, dne, dne, dne, dne,  CL,  C2,  C4, dne, dne}, //01
        {dne, dne, dne, dne, dne,  C1,  C3,  C5, dne, dne}, //02
        {dne, dne, dne, dne, dne,  G4, GC1,  G3, GS1, dne}, //03
        {dne, dne, dne, dne, dne, GC2, dne,  G1,  G2, dne}, //04
        {dne, dne, dne, dne, dne, GS2, dne, GAL, dne, dne}, //05
        {dne, dne, dne, dne, dne, dne,  A5,GALS, dne, dne}, //06
        {dne, dne, dne, dne, dne, dne,  A3,  A1, dne, dne}, //07
        {dne, dne, dne, dne, dne, dne, dne,  A2,  AS, dne}, //08
        { TS,  T4,  T3, dne, dne, dne, dne, dne, dne, dne}, //09
        {dne, TLS,  TL, dne, dne, dne, dne, dne, dne, dne}, //10
    }
};

dne is just static Node dne = new Node();

Here is a link to the constructions of all the objects in map, as it is much too large to paste in directly: http://pastebin.com/Qad46gHh

A Coordinates object essentially is just a container for three ints - x, y, and z, and is constructed with public Coordinates (int z, int y, int x).

This is where the method is being called from:

public ArrayList<Coordinates> makeRoute(String start, String end)
{
    destination = end;
    ArrayList<Coordinates> newCoordArr1 = new ArrayList<Coordinates>();
    ArrayList<Coordinates> newCoordArr2 = new ArrayList<Coordinates>();
    ArrayList<Coordinates> newCoordArr3 = new ArrayList<Coordinates>();
    Coordinates startCoords = world.findCoordsWithRoom(start);
    Coordinates endCoords = world.findCoordsWithRoom(end);
    ArrayList<Coordinates> path = world.makePath(startCoords, endCoords, newCoordArr1, newCoordArr2, newCoordArr3);
    return path;
}

Where, for instance, start is "104" and end is "204" (attached to g2 and G2 respectively), but startCoords and endCoords are both null.

Here is a link to the pathfinding algorithm: http://pastebin.com/NVhSU06w

In the interest of not appearing to be question-spamming in order to draw attention to this, I'd like to state for the record that the other two questions in my question history, while both regarding this same project, are regarding different problems I have encountered with said project.

Was it helpful?

Solution

wouldn't it be simpler to keep a list of all the rooms? – njzk2 Apr 30 at 16:10

Well, I followed this suggestion (made an ArrayList of a custom Pair class, and stored expected input-output in there), and this problem with the project, at least, is solved. I've still no idea what the problem was, unfortunately, but it's part is working, at least.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top