开发者

Incompatible types in java

开发者 https://www.devze.com 2023-03-10 17:46 出处:网络
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 how

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消