Reputation: 415
I don't know if I can explain this and post the proper code to make it clear, but I will try. I have five classes. They are being used to check the validity of an ISBN number. I am getting the error "cannot find symbol - method getISBN(). I have a gui object which I have instantiated. The error comes from the Handler, here:
public void actionPerformed(ActionEvent e)
{
if (e.getSource()==gui.validateButton)
{
try
{
gui.ISBNText.getISBN();/////////////error//////////
gui.status.setText("ISBN " + ISBNText.bookNum + " is valid");
}
catch(ISBNException er)
{
gui.status.setText(er.getMessage());
}
}
else System.exit(0);
I wont post any code from the gui, you get the idea: theres a gui, it has a textfield called ISBNText, and in the ISBNText class, there is a method to retrieve my text, called getISBN, code:
public ISBNText()
{
super(20);
}
//retrieve the ISBN num from textfield
public String getISBN() throws ISBNException
{
bookNum = getText();
validateISBN(bookNum);
return bookNum;
}
I hope this is enough, but not too much, to go on. Any ideas?
Upvotes: 0
Views: 1022
Reputation: 26882
heres a gui, it has a textfield called ISBNText, and in the ISBNText class, there is a method to retrieve my text, called getISBN
Well, if gui.ISBNText is a text field and not an instance of ISBNText class, then it won't be able to find your method.
Your code needs to be something like this:
class Gui {
final ISBNText isbnText = new ISBNText();
}
class Main {
void someMethod(){
Gui gui = new Gui();
gui.isbnText.getISBN();
}
}
Upvotes: 1
Reputation: 692211
Without seeing the GUI class, it's difficult to say. But I would suspect that your ISBNText
field is declared as is :
JTextField ISBNText = new ISBNText();
If that's the case, then getISBN() can't be found because the variable's declared type is JTextField, and not ISBNText. You need to change it to
ISBNText ISBNText = new ISBNText();
Note that public variables should almost never be used, and that variables in Java should always start with a lower-case letter. You should thus call it isbnText
rather than ISBNText
.
Upvotes: 2