Reputation: 332
I am trying to check whether a jTextfield is empty using the following code, then display an error dialog if it is.
if(sproductname.getText().equals("")){
JOptionPane.showMessageDialog(null,"One or more fields is empty","Empty field",JOptionPane.ERROR_MESSAGE);
}
The method is in actionperformed and should be executed when I press a button but in this case nothing happens. What could be wrong is such a small block of code?
Upvotes: 0
Views: 701
Reputation: 5
Ur code didn't working because basic value for object type String is null. Not empty string. All object type in Java have basic value == null.
Upvotes: 0