problem calling function from class to class
Hi guys and girls,
I have this issue. I am having a class which is calling a method findPath upon user click on menu items. Problem is that the function is instantiantiating a class and calls another method in this class. First time is running correctly but second time it doesnt call this function. I can't figure out why. Here is the code
public int[][] findPath(int x, int y, int startPosX, int startPosY){
int pathLength = 0;
PathFinder path = new PathFinder(mapLength,mapWidth,map,startPosX,startP osY,x,y);
pathLength = path.pathLength;
System.err.println("calling function findPath");
if (path.findPath()){
result = new int[pathLength][2];
result = path.outputPath();
}
// for (int i=0;i<result.length;i++){
// System.err.println("result: " + result[i][0] + " ");
//
// }
return result;
}
I am instantiating thie PathFinder class in this method and the path.outputPath() should return me different arrays upon call. But it only calculates once and that's it. Second time is kinda skipping the whole thing.
Can anyone kindly advise me what is going on.
Thank you all.
intializing the same variable twice
I'm not sure what program is supposed to do... it looks like it's recusive, but I'll stay out of that because I don't have enough info. One thing for sure is that you're intializng the same variable twice and then using it in a loop.
Code:
[B][COLOR="Red"]result[/COLOR][/B] = new int[pathLength][2];
[B][COLOR="red"]result[/COLOR][/B] = path.outputPath();
}
// for (int i=0;i<[B][COLOR="red"]result[/COLOR][/B].length;i++)
Change the name of the "result" variable to smoething else... for example:
Code:
[B][COLOR="Red"]arrayResult[/COLOR][/B] = new int[pathLength][2];
[B][COLOR="red"]pathResult[/COLOR][/B] = path.outputPath();
And then use the appropiate varaible name in the "for" loop.
Also, I don't know what you are trying to do here:
Code:
if (path.findPath())
CJSL