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?
Without seeing the GUI class, it’s difficult to say. But I would suspect that your
ISBNTextfield is declared as is :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
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
isbnTextrather thanISBNText.