How to solve java.lang.StackOverflowError in MVC design pattern (plus mySQL) -
i'm using mvc design pattern, , i'm complete beginner in design pattern , java. if didn't put loginmodel login = new loginmodel()); java.lang.nullpointerexception pop up. when put it, java.lang.stackoverflowerror happens. i'm not sure if give enough details, if need more, mention, i'll provide more details..
public class loginmodel { private string username; private int id; private string email; private long starttime; private long endtime; timer timer; private javax.swing.jtextfield jtextfield1; private javax.swing.jtextfield jtextfield2; connection conn = null; resultset rs = null; preparedstatement pst = null; loginmodel login = new loginmodel(); //this error happens public loginmodel(){} public loginmodel(int id,string username,string email){ this.id=id; this.username=username; this.email=email; } public int getid(){ return id; } public string getusername(){ return username; } public string getemail(){ return email; } public void setstarttime(long time){ starttime=time; } public void setendtime(long time){ endtime = time; } public long getusedtime(){ return (endtime-starttime); } public loginmodel(int seconds) { timer = new timer(); timer.schedule(new loginmodel.remindtask(), seconds*1000); } public void settimer(int seconds){ timer = new timer(); timer.schedule(new loginmodel.remindtask(), seconds*1000); } class remindtask extends timertask { public void run() { joptionpane.showmessagedialog(null, "60 seconds left!"); timer.cancel(); } } public void retrievedbase (connection conn){ string sql = "select * customer_info username = ? , password = ?"; string sql2 = "select * admin_info username = ? , password = ?"; string sql11 = "select * customer_info username = ? , password = ? , paidremainingtime != 0"; try{ pst = conn.preparestatement(sql); pst.setstring(1, jtextfield1.gettext()); pst.setstring(2, jtextfield2.gettext()); rs = pst.executequery(); if (rs.next()){ joptionpane.showmessagedialog(null, "welcome "+jtextfield1.gettext()); try{ pst = conn.preparestatement(sql11); pst.setstring(1, jtextfield1.gettext()); pst.setstring(2, jtextfield2.gettext()); rs = pst.executequery(); if (rs.next()){ new dummyhomepage().setvisible(true); //this.setvisible(false); joptionpane.showmessagedialog(null,"your paid time remains " + rs.getint("paidremainingtime")+"minutes"); login.settimer(rs.getint("paidremainingtime")); long starttime = system.currenttimemillis( ); login.setstarttime(starttime); } else{ new purchaseinterface().setvisible(true); //this.setvisible(false); } } catch (exception e){ joptionpane.showmessagedialog(null, e); } } else try{ pst = conn.preparestatement(sql2); pst.setstring(1, jtextfield1.gettext()); pst.setstring(2, jtextfield2.gettext()); rs = pst.executequery(); if (rs.next()){ joptionpane.showmessagedialog(null, "welcome admin "+jtextfield1.gettext()); new manageuserinterface().setvisible(true); //this.setvisible(false); } else joptionpane.showmessagedialog(null, "invalid username , password"); } catch (exception e){ joptionpane.showmessagedialog(null, e); } } catch (exception e){ joptionpane.showmessagedialog(null, e); } } public connection getdbase(){ return conn; } }
loginmodel login = new loginmodel();
login
member variable in case, means it'll created every new object of type loginmodel
.
since creating loginmodel
object creates member variable login
loginmodel
, creates member variable login
loginmodel
... have problem.
Comments
Post a Comment