reset password
Author Message
RandomAccess
Posts: 101
Posted 00:36 Mar 24, 2018 |

I got an InvocationTargetException in the first line of this if statement which I put in a for loop. Anyone know what it means and how I can fix it?

if(m.getSpace()[col][row].getValue() == (E)"S"){
                    x = col;
                    y = row;
                    c = new Coordinate<>(x, y, m.getSpace()[x][y].getValue());
                    lsc.push(c);
                }

Arnav98
Posts: 48
Posted 00:53 Mar 24, 2018 |

I think an InvocationTargetException is thrown when some underlying method being used by your code throws some sort of an exception which just gets wrapped into an InvocationTargetException. For instance if your program throws some runtime exception, it will get wrapped up into an InvocationTargetException.

As far as your code goes, its hard to understand it without knowing where it is placed and how your algorithm generally functions. I did not use any for loop. You basically use a while loop that continues until the stack is not empty. If its empty then no soltuion exists. You move one place forward in either the north, south, east or west direction in each call of the while loop adding the position you move to onto the stack and popping them out as you reach dead ends. The trick here is you need to mark the dead ends so that you dont keep on going towards them again and again. You will also need to play around with your algorithm to keep track for current player position and mark them as well so that you can display the final solution or use a GUI to generate the solution map. As you move forward check each new position to see whether its the target position or the exit point or not. The solution you would get using this type of implementation will use a depth first search to find the solution, which wouldn’t surely be the shortest path to the exit, but will work for this assignment. I still couldn’t figure out whether its possible to find the shortest path or not, but will let you know if I do.

RandomAccess
Posts: 101
Posted 01:11 Mar 24, 2018 |

Upon further research, this may be due to a null point exception on the generic variable reference. Any idea how to reference a generic type without invoking a null point exception?

RandomAccess
Posts: 101
Posted 01:14 Mar 24, 2018 |

The purpose of the for loop is to identify the starting point, which is marked by an "S" in the text documents, to start the stack.

Arnav98
Posts: 48
Posted 01:20 Mar 24, 2018 |
RandomAccess wrote:

The purpose of the for loop is to identify the starting point, which is marked by an "S" in the text documents, to start the stack.

The second line in the input file represents the coordinate for the starting point.

Last edited by Arnav98 at 01:20 Mar 24, 2018.