case "Login":
try {
restoreUserInfo();
String email = textf1.getText();
String password = new String(jpass1.getPassword());
if (hm.containsKey(email)) {
if (hm.get(email).getPassword().equals(password)) {
showMessageDialog(this, "Successfully login");
ch = new Chat_Window("lets chat!!");
System.out.println("after call");
} else {
showMessageDialog(this, "Invalid Password");
}
} else {
showMessageDialog(this, "Invalid Login ID and Password");
}
} catch (Exception exc) {
System.out.println("Invalid file");
exc.printStackTrace();
}
为什么当我调用“ch = new Chat_Window("lets chat!!");”时会出现空指针异常?Chat_window 类在同一个包中可用,并且具有匹配的构造函数,代码如下:
public Chat_Window(String title){
super(title);
setSize(500, 500);
getContentPane().setBackground(Color.LIGHT_GRAY);
setLocationRelativeTo(null);
setResizable(false);
c1=new JPanel();
c2=new JPanel();
lbl=new JLabel("Type Here:");
c1.add(lbl, new GridLayout(1, 2, 50, 50));
ta=new JTextArea(03,30);
c1.add(ta,new GridLayout(1, 2, 50, 50) );
c1.add(send_but,new GridLayout(1, 2, 50, 50));
add(c1, BorderLayout.PAGE_END);
send_but=new JButton("Send");
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
}
请帮忙!!!