我想为我的编辑字段执行验证。所以我正在编写验证ButtonField
。setChangeListener
方法。如果editField
为空并且单击按钮时,我必须显示该字段为空。为了显示我尝试使用status.show()
和dialog.alert()
方法的消息。但两者都在生成一个NullPointerException
. 问题是什么?任何人都可以帮助解决这个问题还是有其他解决方案可以解决这个问题?
我这样写我的代码:
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);
}
}
}
}
});