java - why do i get a null pointer exception when i call the constructor of a another class? -
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 , password"); } } catch (exception exc) { system.out.println("invalid file"); exc.printstacktrace(); } why null pointer exception when call "ch = new chat_window("lets chat!!");"? chat_window class available in same package , matching constructor, code below:
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); } help please!!!
you adding send_but before creating it.
c1.add(send_but,new gridlayout(1, 2, 50, 50)); // send_but null here add(c1, borderlayout.page_end); send_but=new jbutton("send");
Comments
Post a Comment