aspose file tools*
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


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "method ... not found in class ..." Watch "method ... not found in class ..." New topic
Author

method ... not found in class ...

Russ Russ
Greenhorn

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:
"WordGUI.java": Error #: 300 : method display(java.awt.Graphics, int) not found in class assign4.WordStack at line 34, column 13
"WordGUI.java": 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(){
//add(myStack);
wordField = new TextField(20);
add(wordField);
wordField.addActionListener(this);
testButton = new Button("Test for palindromes");
add(testButton);
testButton.addActionListener(this);
}//init()
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);
}//paint()
public void actionPerformed(ActionEvent event){
if(event.getSource() == testButton){
String userInput = wordField.getText();
myStack.evaluate(userInput);
}
repaint();
}//actionPerformed()
}//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];
}//constructor
public int getCapacity(){
return data.length;
}//getCapacity()
public boolean isEmpty(){
return (manyItems == 0);
}//isEmpty()
public char pop(){
if(manyItems == 0){
//throw new EmptyStackException();
}
return data[--manyItems];
}//pop()
public void push(char item){
if(manyItems == data.length){
ensureCapacity(manyItems * 2 + 1);
}
data[manyItems] = item;
manyItems++;
}//push()
public void ensureCapacity(int minimumCapacity){
char biggerArray[];
if(data.length < minimumCapacity){
biggerArray = new char[minimumCapacity];
System.arraycopy(data, 0, biggerArray, 0, manyItems);
data = biggerArray;
}
}//ensureCapacity()
public String evaluate(String userInput){
char charToProcess;
for(int charNum = 0; charNum < userInput.length(); charNum++){
push(userInput.charAt(charNum));
}
}//evaluate()
public void display(Graphics g, int yLoc){
for(int i = 0; i < data.length; i++){
g.drawString("" + data, 25, yLoc);
yLoc += 15;
}
}//display()
}//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:
WordStack.java:57: missing return statement
public String evaluate(String userInput){
Fix that and see if it'll compile....
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Russ,
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
Sheriff

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


JavaBeginnersFaq
"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: http://aspose.com/file-tools
 
subject: method ... not found in class ...
 
Similar Threads
need help with java
Filling Array
help! trouble with pop method
help! trouble with pop method
help! trouble with pop method!