java - Application stop suddenly when trying to login -


after creating inserting username , password signup.java, app stop when login (in emulator), , move signup page in (bluestack). not sure if data being entered in database when signing up.

dbmanager.java

package com.example.student_project;  import com.example.student_project.*;  import android.content.contentvalues; import android.content.context; import android.database.cursor; import android.database.sqlexception; import android.database.sqlite.sqlitedatabase; import android.database.sqlite.sqliteexception; import android.database.sqlite.sqliteopenhelper;   public class dbmanager  {     public static final string key_rowid = "_id";     public static final string key_username = "username";     public static final string key_password = "password";       private static final string database_name= "login.db";     private static final int database_version  = 4;     private static final string  database_table = "login_table";      private static dbhelper ourhelper;     private final context ourcontext;     private static sqlitedatabase ourdatabase;      class dbhelper extends sqliteopenhelper {          public dbhelper(context context) {             super(context, database_name, null, database_version);             // todo auto-generated constructor stub         }          @override         public void oncreate(sqlitedatabase db) {              // todo auto-generated method stub             db.execsql("create table " + database_table + " ( " +              key_rowid + " integer primary key autoincrement , " +             key_username + " text not null , " +              key_password + " text not null );"              );                 }          @override         public void onupgrade(sqlitedatabase db, int oldversion, int newversion) {             // todo auto-generated method stub             db.execsql("drop table if exists " + database_table);             oncreate(db);         }      }       public dbmanager(context c) {     ourcontext = c;     }      public dbmanager open() throws sqlexception{         ourhelper = new dbhelper(ourcontext);         try         {             ourdatabase = ourhelper.getwritabledatabase();         }         catch(sqlexception ex)         {             ourdatabase = ourhelper.getreadabledatabase();         }         return this;     }      public void close() {         ourhelper.close();     }      public long createentry(string username, string password) throws sqlexception     {         // todo auto-generated method stub         contentvalues cv = new contentvalues();         cv.put(key_username, username);         cv.put(key_password, password);         return ourdatabase.insert(database_table, null, cv);      }      public static boolean verifyuser(string username , string password)      {          string columns[] = new string[2];         columns[0] = username;         columns[1] = password;         cursor c= null;         int count=0;         try         {                  // todo auto-generated method stub                 c = ourdatabase.query(database_table, columns,null , null, null, null, null);                 count = c.getcount();          }         catch (sqlexception e)         {             // todo: handle exception             e.printstacktrace();         }                 {             c.close();         }         if(count>0)         {             return true;         }         else         {             return false;         }      } } 

mainactivity.java

package com.example.student_project;  import com.example.student_project.*;  import android.os.bundle; import android.app.activity; import android.content.intent; import android.text.inputfilter.lengthfilter; import android.util.log; import android.view.menu; import android.view.view; import android.view.view.onclicklistener; import android.widget.button; import android.widget.edittext; import android.widget.toast;  public class mainactivity extends activity implements onclicklistener {     private button btn_signup;     private button btn_login;     private edittext et_lusername;     private edittext et_lpassword;      @override     protected void oncreate(bundle savedinstancestate)     {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);          log.i("mytag","this tag");         et_lusername = (edittext) findviewbyid(r.id.et_lusername);         et_lpassword = (edittext) findviewbyid(r.id.et_lpassword);         btn_signup = (button) findviewbyid(r.id.btn_signup);         btn_login = (button) findviewbyid(r.id.btn_login);          btn_login.setonclicklistener(this);         btn_signup.setonclicklistener(this);      }      @override     public boolean oncreateoptionsmenu(menu menu)     {         // inflate menu; adds items action bar if present.         getmenuinflater().inflate(r.menu.main, menu);         return true;     }       @override     public void onclick(view v)     {         // todo auto-generated method stub         switch(v.getid())         {             case r.id.btn_login :             {                 string un = et_lusername.gettext().tostring();                 string pw = et_lusername.gettext().tostring();                  boolean success = dbmanager.verifyuser(un,pw);                 if (success)                 {                     intent = new intent(mainactivity.this,adminmenu.class);                     startactivity(i);                    }                 else                 {                     toast.maketext(getapplicationcontext(), "wrong username or password",toast.length_long);                 }               }             case r.id.btn_signup:             {                 intent = new intent(mainactivity.this,signup.class);                 startactivity(i);                }         }     }     } 

signup.java

package com.example.student_project;   import com.example.student_project.*;  import android.os.bundle; import android.app.activity; import android.app.dialog; import android.content.intent; import android.view.menu; import android.view.view; import android.view.view.onclicklistener; import android.widget.button; import android.widget.edittext; import android.widget.textview; import android.widget.toast;  public class signup extends activity implements onclicklistener { private button btn_add; private edittext et_username; private edittext et_password; private edittext et_confirmpassword; @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.signup);      et_username = (edittext) findviewbyid(r.id.et_username);     et_password = (edittext) findviewbyid(r.id.et_password);     et_confirmpassword = (edittext) findviewbyid(r.id.et_confirmpassword);     btn_add = (button) findviewbyid(r.id.btn_add);      btn_add.setonclicklistener(this); }  @override public boolean oncreateoptionsmenu(menu menu) {     // inflate menu; adds items action bar if present.     getmenuinflater().inflate(r.menu.main, menu);      return true; }  @override public void onclick(view v) {     // todo auto-generated method stub     switch(v.getid())     {     case r.id.btn_add :          boolean diditwork = true;                  try           {             string username = et_username.gettext().tostring();              string password = et_password.gettext().tostring();              string cpassword = et_confirmpassword.gettext().tostring();               if(password.equalsignorecase(cpassword))              {                  dbmanager empty = new dbmanager(signup.this);                  empty.open();                  empty.createentry(username,password);                  empty.close();                    intent addintent = new intent(signup.this,mainactivity.class);                     startactivity(addintent);              }              else               {                  toast.maketext(getapplicationcontext(), "passwords not match", toast.length_long);              }          }           catch (exception e)          {             diditwork = false;             dialog d = new dialog(this);             string error = e.tostring();             d.settitle("dang");             textview tv = new textview(this);             tv.settext(error);             d.setcontentview(tv);             d.show();         }         /*          {             if(diditwork)             {             dialog d = new dialog(this);             d.settitle("hech ya");             textview tv = new textview(this);             tv.settext("success");             d.setcontentview(tv);             d.show();             }          } */       } }  } 

admin.java

package com.example.student_project;  import android.os.bundle; import android.app.activity; import android.content.intent; import android.view.menu; import android.view.view; import android.view.view.onclicklistener; import android.widget.button; import android.widget.edittext;  public class adminmenu extends activity {      @override     protected void oncreate(bundle savedinstancestate)     {         super.oncreate(savedinstancestate);         setcontentview(r.layout.admin_menu);    }  @override public boolean oncreateoptionsmenu(menu menu) {     // inflate menu; adds items action bar if present.     getmenuinflater().inflate(r.menu.main, menu);     return true; } } 

logcat error

    w/activitymanager(  293): unbind failed: not find connection android.os.binderproxy@410ce000  i/choreographer( 1994): skipped 55 frames!  application may doing work on main thread.  d/androidruntime( 1994): shutting down vm  w/dalvikvm( 1994): threadid=1: thread exiting uncaught exception (group=0x40a71930)  e/androidruntime( 1994): fatal exception: main  e/androidruntime( 1994): java.lang.nullpointerexception  e/androidruntime( 1994):    @ com.example.student_project.dbmanager.verifyuser(dbmanager.java:110)  e/androidruntime( 1994):    @ com.example.student_project.mainactivity.onclick(mainactivity.java:61)  e/androidruntime( 1994):    @ android.view.view.performclick(view.java:4204)  e/androidruntime( 1994):    @ android.view.view$performclick.run(view.java:17355)  e/androidruntime( 1994):    @ android.os.handler.handlecallback(handler.java:725)  e/androidruntime( 1994):    @ android.os.handler.dispatchmessage(handler.java:92)  e/androidruntime( 1994):    @ android.os.looper.loop(looper.java:137)  e/androidruntime( 1994):    @ android.app.activitythread.main(activitythread.java:5041)  e/androidruntime( 1994):    @ java.lang.reflect.method.invokenative(native method)  e/androidruntime( 1994):    @ java.lang.reflect.method.invoke(method.java:511)  e/androidruntime( 1994):    @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:793)  e/androidruntime( 1994):    @ com.android.internal.os.zygoteinit.main(zygoteinit.java:560)  e/androidruntime( 1994):    @ dalvik.system.nativestart.main(native method)  w/activitymanager(  293):   force finishing activity com.example.student_project/.mainactivity  w/windowmanager(  293): failure taking screenshot (246x410) layer 21020 

it because cursor c null..and u have'nt caught nullpointerexception in catch block in verifyuser()..change sqlexception in catch exception catch exceptions..


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -