Java won't recognize function

Started by
7 comments, last by Zahlman 14 years, 5 months ago
delOrder[count] = getData(infantCircle.deleteNode(infantCircle.getNode(k)));
This should be all you need. All of the functions accept Node as their parameter and return a Node also. The error I get says it "cannot find symbol" at getData(), and it's probably because for some reason it doesn't think it's getting a Node as a parameter. Help would be appreciated. Thanks!
Advertisement
Well, I'll ask the obvious question:

Where is getData defined?
Split that long line into four lines and tell us in which line the error message appears and paste it here verbatim.
delOrder[count] =getData(infantCircle.deleteNode(infantCircle.getNode(k)));
Also post the exact error message. The most likely reason (assuming it's not a typo) is that you have a scope visibility problem somewhere, but then it's unlikely to be getData() but might be delOrder or any of those other things. Check that everything is visible at the level it needs to be, or post the relevant classes.

One little thing - in Java we call them methods, not functions.

Eclipse or NetBeans would catch this error for your before the compiler does.
It's defined in the Circular_Linked_List class (not the one included in the java library), as getNode and deleteNode.

I might as well include the definitions.

public Node getNode(int index) // returns a node from the list	{		if (index > (size - 1))			return null;				Node temp = getFirst();		for (int i = 0; i < index; i++)		{			temp = temp.next;		}		return temp;	}public Node deleteNode(Node delNode) // deletes a node	{		int index = checkNode(delNode);			if (index == -1)			System.out.println("Node doesn't exist");				Node temp = getNode(index - 1);				if(index == (size - 1))		{				Node del = last;			temp.next = last.next;			last = temp;			size--;			return del;		} else		{			Node del = temp.next;			temp.next = temp.next.next;			temp.next.next = null;			size--;			return del;		}	}public int getData(Node myNode) // returns data of node		{			return myNode.data;		}



Here's the error message after splitting it into four lines (it appears at getData):

AmStramGram.java:64: cannot find symbolsymbol  : method getData(Circular_Linked_List.Node)location: class AmStramGram			getData(			^1 error

getData() is in Circular_Linked_List? Is the method calling getData() also in Circular_Linked_List? Okay, I see it doesn't seem to be. You can't call a method of another class without any qualifier (object reference for non-static methods and class name for static methods, so eg: myList.getData()).
The method calling getData is in a different class.

Yeah, that was it. Stupid little mistake, didn't even occur to me you couldn't do that for some reason.

Thanks for the help, and very quick replies.
No problem. :)
Quote:Original post by Gixugif
The method calling getData is in a different class.

Yeah, that was it. Stupid little mistake, didn't even occur to me you couldn't do that for some reason.


Because they're methods, not functions. A method requires an instance of the class to be called upon.

This topic is closed to new replies.

Advertisement