Q:

Getting NullPointerException For Showing the status (or) alert if edifield is empty

I want to perform validations for my editfields.so I am writing the validations on ButtonField.setChangeListener method. If editField is empty and when clicking on the button i have to show that the field is empty. To show the message i tried by using both status.show() and dialog.alert() methods. But both are generating a NullPointerException. What is the problem? Can anyone help to solve this problem or are there any other solutions to this problem?
I have written my code like this:
btnencrypt = new ButtonField("Encrypt");
        btnencrypt.setChangeListener(new FieldChangeListener() {

            public void fieldChanged(Field field, int context) {
                // TODO Auto-generated method stub

                //getphonenos();
                System.out.println("savedPhone no are in compose encrypt:"+savedphoneno);
                encryptClicked= true;

                if (savedphoneno.equals("")) { **Getting the exception here....**

                    Dialog.alert("Please select valid contact");     
                } else {
                    if (!(savedphoneno.equals(""))) {

                        if (edmsg.getText().toString().trim().equals("")) {
                            Dialog.alert("Please enter message");

                        }else {

                            int index = savedphoneno.indexOf(",");
                            if (index < 0) {
                                encryptBTNClicked = true;
                                try {
                                    base64msgString = encrypt(savedphoneno);
                                } catch (CryptoException e) {
                                    // TODO Auto-generated catch block
                                    e.printStackTrace();
                                } catch (IOException e) {
                                    // TODO Auto-generated catch block
                                    e.printStackTrace();
                                }
                                edencryptmsg.setText(base64msgString);
                            } else {
                                //encryptTV.setText("");
                                edencryptmsg
                                .setText("Sending data to multiple receipients,"
                                        + "can't show the encrypted msg,as it varies");
                                //edencryptmsg.setTextColor(Color.MAGENTA);
                            }
                            btnencrypt.setEnabled(false);
                            btnclear.setEnabled(false);
                        }

                    }

                }
            }

        });

A:

I have a useful method that I put into my StringUtils class that checks if a string is valid.
/**
 * Tests if a string is a non-null, non-empty string. This can be called to
 * determine if the string should be displayed, or not.
 * 
 * @param text
 *        String to test.
 * @return
 *         If <code>text</code> is <code>null</code>, returns
 *         <code>false</code>. <br>
 *         If <code>text</code> is an empty string (""), returns
 *         <code>false</code>. <br>
 *         Else returns <code>true</code>.
 */
public static boolean isNonBlankString(String text)
{
    // null text -> false
    if (text == null)
        return false;

    // empty text -> false
    if ("".equals(text))
        return false;

    return true;
}

This will help you with Rupak's answer.

