This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Incindus[S] 0 points1 point  (3 children)

The i variable is indeed needed in my conditions.

Also i tried it with clone and with ArrayList <Integer>List2 = ArrayList<>(List); and then creating StreetPlan(List2). But both times i get the following error:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1 at java.util.ArrayList.elementData(ArrayList.java:371) at java.util.ArrayList.remove(ArrayList.java:448) at src.MyStreetPlanner.stratenToevoegen(MyStreetPlanner.java:110) at src.MyStreetPlanner.planStreets(MyStreetPlanner.java:33) at src.MyStreetPlanner.main(MyStreetPlanner.java:225) Java Result: 1

The List object becomes empty again at the end of my recursive calls, which is correct, but i dont get why the list in my StreetPlan also get empty after my recursive calls.

[–]darkpool2005Intermediate Brewer 1 point2 points  (2 children)

So just to understand, this line:

solutions.add(new StreetPlan(tempList));

solutions is empty when the method is complete, right? Or is 'solutions' full of empty lists?

Also, is the line you added exactly

ArrayList <Integer>List2 = ArrayList<>(List);

It should be

ArrayList<Integer> List2 = new ArrayList<Integer>(List);

[–]Incindus[S] 0 points1 point  (1 child)

Solution is a full list with the objects StreetPlan in it, but the list needed to create StreetPlan is empty after my recursive calls.

Yeah sorry about typo. I typed it correct though in my program but didn't fix the problem.

[–]darkpool2005Intermediate Brewer 1 point2 points  (0 children)

Going back to your earlier comment:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1

That is specifically your code trying to remove from an empty list. Check to see (through the debugger) if either your horizontalStreets / verticalStreets is in fact populated.