I'm Trying To Make A Chat Bot But It Always Comes Up With A Error When I Type:
if(Write == "hi"){
Reply.setText("HI!");
}
It Will Come With The Error: jtextarea incomparable with String
What Shall I Do?
I'm Trying To Make A Chat Bot But It Always Comes Up With A Error When I Type:
if(Write == "hi"){
Reply.setText("HI!");
}
It Will Come With The Error: jtextarea incomparable with String
What Shall I Do?
Not much context in the question to work with, but I suppose you are looking for
if ("hi".equals(Write.getText()))
By the way, never compare strings with == unless you really want them to be exactly the same instance of the String class.
You can not compare completely different objects with each other by using ==. Write is of type JTextArea and "hi" is of type String. Those objects have nothing in common thus the compiler complaints.
You probably wanted to compare the text stored inside JTextArea with the text "hi". You access this text by using the JTextArea#getText method (documentation).
Now note that you never (except you know what you do) should compare Strings by using ==. The result will not be what you expected. Use String#equals instead. Here's more on this topic: How do I compare strings in Java?
So your code should probably look like:
if ("hi".equals(Write.getText())) {
Reply.setText("HI!");
}
Last note that you should stick to naming conventions. Variable names, also method names, should always begin with a lowercase character. Uppercase is only used for class names (and constants). So you should rather write write and reply:
if ("hi".equals(write.getText())) {
reply.setText("HI!");
}