Incompatible types in java
I am trying to take a String
from a JTextField
using getText
and apply it to the method
SearchString
but i am presented with the error Incompatible Types i cannot see anything wrong with this code however.
ActionListner code:
String whatToSearch,result
JTextField searchfield
method SearchString
EDIT: have changed to Publ开发者_运维百科ic String, but i am now given a Missing Return Statement error at the line shown above
The compilation error is saying that you can't assign the result of SearchString(whatToSearch)
to result
. This is because SearchString
is declared to return NO result; that's what void
means!
The fix is to change the signature to public String SearchString(String input) ...
and change the body to return a String value at the appropriate point or points.
精彩评论