Hi all,
I am makinga text editor in Java
I am trying to implement the search function but am having problems:
I have a class called SearchDialog, which contains (amongst others) the following method:
Code:
protected String getText() {
return target.getText();
}
So therefore when one enters text in a search dialog box, the string that they enter is retrieved by this method.
Now I need to actually get this info. I am writing another method to do this. I need to get the string, and then I can use the indexOf() method to find the search string in a certain string.
So far, my method looks like this:
Code:
public void Search(){
String searchString = searchDialog.getText();
System.out.println("The search term is: " + searchString);
//other command to come here, I am just testing at the moment.
}
But I am getting this error:
Code:
non-static method getText() cannot be referenced from a static context
String searchString = SearchDialog.getText();
^
Whats going wrong, why can't I access it? Please help!!!!