0
if(txtValueUIT.getText()==null || txtValueDolar.getText()==null || txtValueUIT.equals("") || txtValueDolar.equals(""))
JOptionPane.showMessageDialog(null, "You have not entered both values", "Error", JOptionPane.ERROR_MESSAGE);

What I try to do is to show the Error Message when the JTextFfields are empty or null. I am using if and it shows no bugs but when testing it it simply won't show the message when it is supposed to do it.

*It seems it doesn't perform any action at all because the code that follows in that method, when there is a value missing in those JtextFields, won't be processed. *

The code that follows is a setText to another component using as parameters Strings that get the Text from the JTextFields

By the way:

if(e.getSource() == btnRefresh) //I added the button with an action listener
refreshValues(); //this contains the code with the JOptionPane
corlaez
  • 1,352
  • 1
  • 15
  • 30
  • .getText() never return null try system.out.println(txtValueDolar.getTExt()) to check it out. – JackTools.Net Nov 17 '13 at 16:44
  • Post an SSCCE. We can't deduce anything from those code snippets alone. – JB Nizet Nov 17 '13 at 16:44
  • if(e.getSource().equals(btnRefresh)) – iShaalan Nov 17 '13 at 16:44
  • thanks Shaalan that seems to improve my code style. BTW I did try to read other methods and I performed some options... I am not sure if the problem is the String comparison it seems that since the String is null the method doesnt want to perform as the parsers don't get any value or something... – corlaez Nov 17 '13 at 16:49
  • @JackTools.Net HOWEVER , It will Throw NullPointrException – iShaalan Nov 17 '13 at 16:51
  • @iShaalan then it is clear why hi says: *It seems it doesn't perform any action at all because the code that follows in that method, when there is a value missing in those JtextFields, won't be processed. * – JackTools.Net Nov 17 '13 at 16:55
  • I am not complete sure. I guess the parsers that follow> `UIT=Double.parseDouble(txtValorUIT.getText());` `priceDolar=Double.parseDouble(txtValorDolar.getText());` made the method to stop when taking `""` or `null` values. I am fairly new and i found doubts everywhere. – corlaez Nov 17 '13 at 17:07

1 Answers1

4

Have a try with the following code:

From

txtValueUIT.equals("") || txtValueDolar.equals("")

To

txtValueUIT.getText().equals("") || txtValueDolar.getText().equals("")
Mengjun
  • 3,159
  • 1
  • 15
  • 21
  • `if (txtValorUIT.getText().matches("[a-z\\-_]+ ") ||` `txtValorDolar.getText().matches("[a-z\\-_]+ ")` `|| txtValorUIT.getText().isEmpty() ||` `txtValorDolar.getText().isEmpty() )` `{JOptionPane.showMessageDialog(null, "No ha ingresado ambos` `valores", "Error", JOptionPane.ERROR_MESSAGE);` `return;}` This works like charm. Even null will show the dialog. – corlaez Nov 17 '13 at 17:16
  • if (txtValorUIT.getText().matches(".*[1-9\\.]+.*" && txtValueUIT.getText().matches(".*[1-9\\.]+.*") {PARSERS, SETTEXTS} else SHOWMESSAGE //THIS IS MUCH EFFICIENT – corlaez Nov 17 '13 at 18:49