Results 1 to 4 of 4
- 12-19-2008, 02:23 PM #1
Member
- Join Date
- Dec 2008
- Posts
- 11
- Rep Power
- 0
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.
- 12-19-2008, 03:49 PM #2
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.
Java 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++)
Java Code:[B][COLOR="Red"]arrayResult[/COLOR][/B] = new int[pathLength][2]; [B][COLOR="red"]pathResult[/COLOR][/B] = path.outputPath();
Also, I don't know what you are trying to do here:
Java Code:if (path.findPath())
Chris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
- 12-19-2008, 08:31 PM #3
Member
- Join Date
- Dec 2008
- Posts
- 11
- Rep Power
- 0
the if statement is coz the find path function in the other class returns true or false. i mean is either finding a path or not.i will try with ur suggestion see what happends.
Thanks. I hope it does someting good :)
- 12-19-2008, 08:35 PM #4
Member
- Join Date
- Dec 2008
- Posts
- 11
- Rep Power
- 0
well even if i commented the first result = new int[][] and then use just path.outputpath() it still holds the same result from the first call. same array. i will try again the same thing.. go through the code line by line but i am already sick of it. If u have any other suggestions please do not hezitate not even a second. And thank you for the time u put in answering my call.
Similar Threads
-
Stack class/problem in stackSize Initialization and usage of pop() function
By Mazharul in forum New To JavaReplies: 1Last Post: 11-17-2008, 10:32 AM -
Register a callback function in other class
By barts2108 in forum New To JavaReplies: 2Last Post: 11-10-2008, 05:24 PM -
Calling a method in a different class from within a method problem
By CirKuT in forum New To JavaReplies: 29Last Post: 09-25-2008, 08:55 PM -
Calling a method on original class from created class
By kpedersen in forum Advanced JavaReplies: 4Last Post: 08-20-2008, 01:25 AM -
Problem calling another class
By adlb1300 in forum New To JavaReplies: 3Last Post: 10-25-2007, 03:05 PM
Bookmarks