File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes method ... not found in class ... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "method ... not found in class ..." Watch "method ... not found in class ..." New topic

method ... not found in class ...

Russ Russ

Joined: Oct 21, 2002
Posts: 4
I am having trouble with my GUI class not recognizing methods from a STACK class from the same package. Here's the skinny:
I have a GUI class named WordGUI.
I hava a STACK class named WordStack.
within WordGUI I instantiate an instance of a WordStack and call it myStack. Example below:
WordStack myStack = new WordStack();
When I call WordStack methods from WordGUI I get the error messages even though display and evaluate are methods from WordStack:
"": Error #: 300 : method display(java.awt.Graphics, int) not found in class assign4.WordStack at line 34, column 13
"": Error #: 300 : method evaluate(java.lang.String) not found in class assign4.WordStack at line 42, column 15
Complete code for both classes is below:

WordGUI class:
package assign4;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class WordGUI extends Applet implements ActionListener{
WordStack myStack = new WordStack();
private Button testButton;
private TextField wordField;
public void init(){
wordField = new TextField(20);
testButton = new Button("Test for palindromes");
public void paint (Graphics g){
g.drawString("Enter a word in the textField above and click", 25, 100);
g.drawString("the button to check if the word is a palindrome", 25, 115);
myStack.display(g, 150);
public void actionPerformed(ActionEvent event){
if(event.getSource() == testButton){
String userInput = wordField.getText();
}//class WordGUI
WordStack class:
package assign4;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class WordStack implements Cloneable{
private char[] data;
private int manyItems;
public WordStack(){
final int initialCapacity = 20;
manyItems = 0;
data = new char[initialCapacity];
}//generic constructor
public WordStack(int initialCapacity){
if(initialCapacity < 0){
throw new IllegalArgumentException
("initialCapacity too small: " + initialCapacity);
manyItems = 0;
data = new char[initialCapacity];
public int getCapacity(){
return data.length;
public boolean isEmpty(){
return (manyItems == 0);
public char pop(){
if(manyItems == 0){
//throw new EmptyStackException();
return data[--manyItems];
public void push(char item){
if(manyItems == data.length){
ensureCapacity(manyItems * 2 + 1);
data[manyItems] = item;
public void ensureCapacity(int minimumCapacity){
char biggerArray[];
if(data.length < minimumCapacity){
biggerArray = new char[minimumCapacity];
System.arraycopy(data, 0, biggerArray, 0, manyItems);
data = biggerArray;
public String evaluate(String userInput){
char charToProcess;
for(int charNum = 0; charNum < userInput.length(); charNum++){
public void display(Graphics g, int yLoc){
for(int i = 0; i < data.length; i++){
g.drawString("" + data, 25, yLoc);
yLoc += 15;
}//class WordStack
Any help would be appreciated greatly. Thank you
[ October 22, 2002: Message edited by: Thomas Paul ]
Dave Landers
Ranch Hand

Joined: Jul 24, 2002
Posts: 401
I doubt that you get those errors when you call any method, but probably when you try to compile.
I'm not sure what you're using (probably some IDE thingy), but if you compile the code with javac, you'd get: missing return statement
public String evaluate(String userInput){
Fix that and see if it'll compile....
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
Welcome to JavaRanch!
When posting code, please be sure to surround the code with the [code] and [/code] UBB Tags. This will help to preserve the formatting of the code, thus making it easier to read and understand. Let's see what it would look like:

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Marilyn de Queiroz

Joined: Jul 22, 2000
Posts: 9059
Closing this thread in favor of this duplicate thread.

"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
I agree. Here's the link:
subject: method ... not found in class ...
It's not a secret anymore!