做了个数字键盘式样的登录界面,只要在“editTf”输入密码,点击确定按钮激活"keyOk"命令就出现错误信息“Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException”
如下图,请有经验的智者帮忙指导下怎么解决这个问题。
private void initComponents() {
HmiSettings.m1Handler = new M1Handler(hmiSettings);
// The user is logged in
if(currentOnLineStat) {
if (HmiSettings.status.getLoggedOn()) {
screenPanel.loginutil.exit();
} else {
setLogOff();
}
} else {
String strLogOn = HmiSettings.lngManager.getString("strings", "strLogOnCode");
LockDialog key = new LockDialog(hmiSettings.appFrame, strLogOn, "keyLogOn", true);
key.setShowLimits(false);
key.setShowOldValue(false);
key.setDotAllowed(false);
key.setMinusAllowed(false);
//key.setStringBackspace(hmiSettings.strBackspace);
//key.setStringCancel(hmiSettings.strCancel);
//key.setStringOk(hmiSettings.strOk);
//key.setStringOld(hmiSettings.strOld);
//key.setStringMin(hmiSettings.strMin);
//key.setStringMax(hmiSettings.strMax);
key.setEchoChar('*');
key.addLockListener(this);
key.setVisible(true);
key.toFront();//将窗口至于前端
}
setPage("scrHome");//取消后,登录、退出系统无影响
}
private void setPage(String page) {
if(currentOnLineStat && !page.equals("scrHome")) { // No returning home wanted after log on/off
screenPanel.setPage(page);
}
}
public void navigationCommand(String cmd) {
setPage(cmd);
}
public void setLogOff(){
if(HmiSettings.status.getLoggedOn()) {
HmiSettings.status.setLoggedOn(false);
screenPanel.setLogOn(false);
}
}
public void setLogOn() {
if (!HmiSettings.status.getLoggedOn()) {
HmiSettings.status.setLoggedOn(true);
screenPanel.setLogOn(true);
}
}
public void lockNewValue(LockEvent evt) {
String name = evt.getName();
if(name.equals("keyLogOn"))
if(hmiSettings.keyPadCode.equals(evt.getString())) {
HmiSettings.status.setLoggedOn(true);
**351行:** screenPanel.setLogOn(HmiSettings.status.getLoggedOn());
}
}
if(cmd.equals("keyOk")) {
boolean valOk = false;
String sVal = editTf.getText();
double dVal = 0.0;
int iVal = 0;
try {
dVal = Double.valueOf(sVal).doubleValue();
iVal = Integer.valueOf(sVal).intValue();
}
catch (NumberFormatException e) {
}
if(useLimits) {
if(isInteger) {
if((iVal >= iMinValue) && (iVal <= iMaxValue)) {
valOk = true;
}
}
else {
if((dVal >= dMinValue) && (dVal <= dMaxValue)) {
valOk = true;
}
}
} else {
valOk = true;
}
if(valOk)
if((sVal.equals("00000")) && (sVal != null && !"".equals(sVal))) {//sVal.equals("64826"),sVal.equals(hmiSettings.keyPadCode.equals("64826"))
**541行:** sendNewValue(dVal, iVal, sVal);
JOptionPane.showMessageDialog(null, "密码正确!");
dispose();//关闭当前窗口
} else if(sVal.equals("")){//if (new String(editTf.getText()).trim().equals(""))sVal.equals("")
JOptionPane.showMessageDialog(null, "未填写密码!");
}
else
{
JOptionPane.showMessageDialog(null, "密码错误!");
editTf.setText("");
}
}
private void sendNewValue(double dVal, int iVal, String sVal) {
if(!listeners.isEmpty()) {
LockEvent val = new LockEvent(this, dVal, iVal, sVal, name);
for(int i = 0; i < listeners.size(); i++) {
LockListener listener = (LockListener) listeners.elementAt(i);
**601行:** listener.lockNewValue(val);
}
}
}
import java.util.EventObject;
public class LockEvent extends EventObject {
private double dValue;
private int iValue;
private String sValue;
private String name;
public LockEvent(Object source, double v, int i, String s, String n) {
super(source);
dValue = v;
iValue = i;
sValue = s;
name = n;
}
public double getDouble() {
return dValue;
}
public int getInt() {
return iValue;
}
public String getString() {
return sValue;
}
public String getName() {
return name;
}
}