| Author |
Stack.peek() Error
|
nani aman
Ranch Hand
Joined: Sep 22, 2004
Posts: 33
|
|
Hi all friendly ranch hand. I have an error which i couldn't figure out. It look simple but i still couldn't solve it by myself. error 1 symbol : method peek () location: class Stack top = stack.peek(); error 2 symbol : method equal (java.lang.String) location: class java.lang.String else if(!(top.equal(c1))) {stack.push(c1);} this is my part of code: i have import java.lang.String and declare the stack. So why this error occurs? Thanks kind ranch hands. [ changed \ to / -ds ] [ October 23, 2004: Message edited by: Dirk Schreckmann ]
|
 |
David Harkness
Ranch Hand
Joined: Aug 07, 2003
Posts: 1646
|
|
Both messages mean that the compiler cannot find a method with a matching name and signature (sequence and types of parameters).Since that says "Stack" and not "java.util.Stack", I assume Stack is your own class. Check the method name and signature. That looks like a correct definition of a peek() method, but without Stack's definition I can only guess.This one is looking for a method named "equal" in class String that takes a String (or one of its superclass/interfaces, like Object). Look in the JavaDocs for String and you'll see that it overrides the method "boolean equals(Object)" from Object (note the "s"). Here's a free pointer:This is equivalent to [ October 22, 2004: Message edited by: David Harkness ]
|
 |
nani aman
Ranch Hand
Joined: Sep 22, 2004
Posts: 33
|
|
Actually i use Class Stack in java.util and i already using java.util.*. For stack.peek(), it receive String data type and i put at variable top to compare. I have see the JavaDoc but how to define wrong? wish you can guide me. :roll:
|
 |
Jimmy Die
Ranch Hand
Joined: Nov 20, 2003
Posts: 97
|
|
Hi, your method definition equal() correct? Or you should equals() with an 's'.
|
Jimmy Die
|
 |
David Harkness
Ranch Hand
Joined: Aug 07, 2003
Posts: 1646
|
|
Originally posted by nani aman: Actually i use Class Stack in java.util and i already using java.util.*. For stack.peek(), it receive String data type and i put at variable top to compare. I have see the JavaDoc but how to define wrong?
Given that the error message says "class Stack" and not "class java.util.Stack" (note that the other error message says "java.lang.String"), I would guess you have a variable named "Stack" with a capital S or you have defined your own Stack class. If you post your code we'll be able to help you.
|
 |
 |
|
|
subject: Stack.peek() Error
|
|
|