android - Unable to register in the Registration(Table not getting inserted) -


i have tried create registration , login page.but when trying register,the field values not getting inserted.this code

mainactivity.java

package com.example.login1;  import android.support.v7.app.actionbaractivity; import android.support.v7.app.actionbar; import android.support.v4.app.fragment; import android.app.activity; import android.content.context; import android.content.intent; import android.database.cursor; import android.database.sqlite.sqlitedatabase; import android.os.bundle; import android.view.layoutinflater; import android.view.menu; import android.view.menuitem; import android.view.view; import android.view.viewgroup; import android.view.view.onclicklistener; import android.widget.button; import android.widget.edittext; import android.widget.toast; import android.os.build;  public class mainactivity extends activity implements onclicklistener  {      button mlogin;     button mregister;      edittext muname;     edittext mpassword;      dbhelper db = null;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_login);          mregister = (button) findviewbyid(r.id.register);         mregister.setonclicklistener(this);          mlogin = (button) findviewbyid(r.id.login);         mlogin.setonclicklistener(this);      }      public void onclick(view v) {         switch (v.getid()) {          case r.id.register:             intent = new intent(getbasecontext(), registration.class);             startactivity(i);             break;          case r.id.login:              muname = (edittext) findviewbyid(r.id.ledituname);             mpassword = (edittext) findviewbyid(r.id.leditpw);              string username = muname.gettext().tostring();             string password = mpassword.gettext().tostring();              if (username.equals("") || username == null) {                 toast.maketext(getapplicationcontext(),                         "please enter user name", toast.length_short).show();             } else if (password.equals("") || password == null) {                 toast.maketext(getapplicationcontext(),                         "please enter password", toast.length_short)                         .show();             } else {                 boolean validlogin = validatelogin(username, password,                         getbasecontext());                 if (validlogin) {                     // system.out.println("in valid");                     //intent in = new intent(getbasecontext(), tabbar.class);                     // in.putextra("username", muname.gettext().tostring());                     //startactivity(in);                     intent i1 = new intent(getbasecontext(), welcome.class);                     toast.maketext(getapplicationcontext(),                             "success valid login", toast.length_short)                             .show();                     startactivity(i1);                     // finish();                 }             }             break;          }      }      private boolean validatelogin(string username, string password,             context basecontext) {         db = new dbhelper(getbasecontext());         sqlitedatabase db = db.getreadabledatabase();          string[] columns = { "_id" };          string selection = "username=? , password=?";         string[] selectionargs = { username, password };          cursor cursor = null;         try {              cursor = db.query(dbhelper.database_table_name, columns, selection,                     selectionargs, null, null, null);             startmanagingcursor(cursor);         } catch (exception e)          {             e.printstacktrace();         }         int numberofrows = cursor.getcount();          if (numberofrows <= 0) {              toast.maketext(getapplicationcontext(),                     "user name , password miss match..\nplease try again",                     toast.length_long).show();             intent intent = new intent(getbasecontext(), mainactivity.class);             startactivity(intent);             return false;         }          return true;      }      public void ondestroy() {         super.ondestroy();         db.close();     } } 

registration.java

package com.example.login1;  import android.app.activity; import android.content.contentvalues; import android.content.intent; import android.database.sqlite.sqlitedatabase; import android.os.bundle; import android.view.view; import android.view.view.onclicklistener; import android.widget.adapterview; import android.widget.adapterview.onitemselectedlistener; import android.widget.arrayadapter; import android.widget.button; import android.widget.edittext; import android.widget.spinner; import android.widget.toast;  public class registration extends activity implements onclicklistener, onitemselectedlistener   {     private button msubmit;     private button mcancel;      private edittext mfname;     private edittext mlname;     private spinner mgender;     private edittext memail;     private edittext mphno;     private edittext madd;     private edittext mbloodgroup;     private edittext mdob;     private edittext mfathername;     private edittext mmothername;     private edittext musername;     private edittext mpass;     private edittext mcpass;      private string gen;        protected dbhelper db = new dbhelper(registration.this);     @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.register);           // assignment of ui fields variables         msubmit = (button) findviewbyid(r.id.submit);         msubmit.setonclicklistener(this);          mcancel = (button) findviewbyid(r.id.cancel);         mcancel.setonclicklistener(this);          mfname = (edittext) findviewbyid(r.id.efname);         mlname = (edittext) findviewbyid(r.id.elname);         mgender = (spinner) findviewbyid(r.id.spinner1);         memail = (edittext) findviewbyid(r.id.eemail);         mphno = (edittext) findviewbyid(r.id.ephnno);         madd = (edittext) findviewbyid(r.id.eadd);         mbloodgroup = (edittext) findviewbyid(r.id.ebloodgroup);         mdob = (edittext) findviewbyid(r.id.edob);         mfathername = (edittext) findviewbyid(r.id.efathername);         mmothername = (edittext) findviewbyid(r.id.emothername);         musername = (edittext) findviewbyid(r.id.eusername);         mpass = (edittext) findviewbyid(r.id.epass);         mcpass = (edittext) findviewbyid(r.id.ecpass);          // spinner method read on selected value         arrayadapter<state> spinnerarrayadapter = new arrayadapter<state>(this,                 android.r.layout.simple_spinner_item, new state[] {                         new state("male"), new state("female") });         mgender.setadapter(spinnerarrayadapter);         mgender.setonitemselectedlistener(this);     }          @override         public void onclick(view v) {              switch (v.getid()) {              case r.id.cancel:                 intent = new intent(getbasecontext(),mainactivity.class);                 startactivity(i);                 // finish();                 break;              case r.id.submit:                   string fname = mfname.gettext().tostring();                  string lname = mlname.gettext().tostring();                  string email = memail.gettext().tostring();                  string phoneno = mphno.gettext().tostring();                   string address = madd.gettext().tostring();                  string bloodgroup = mbloodgroup.gettext().tostring();                  string dob = mdob.gettext().tostring();                  string father = mfathername.gettext().tostring();                   string mother = mmothername.gettext().tostring();                  string username = musername.gettext().tostring();                  string password = mpass.gettext().tostring();                  string cpassword= mcpass.gettext().tostring();                  boolean invalid = false;                  if (fname.equals("")) {                     invalid = true;                     toast.maketext(getapplicationcontext(), "enter firstname",                             toast.length_short).show();                 } else                  if (lname.equals("")) {                     invalid = true;                     toast.maketext(getapplicationcontext(),                             "please enter lastname", toast.length_short)                             .show();                 } else                  if (email.equals("")) {                     invalid = true;                     toast.maketext(getapplicationcontext(),                             "please enter username", toast.length_short)                             .show();                 } else                  if (phoneno.equals("")) {                     invalid = true;                     toast.maketext(getapplicationcontext(),                             "please enter password", toast.length_short)                             .show();                  } else if (address.equals("")) {                     invalid = true;                     toast.maketext(getapplicationcontext(),                             "please enter email id", toast.length_short)                             .show();                 }                  else if (bloodgroup.equals("")) {                     invalid = true;                     toast.maketext(getapplicationcontext(),                             "please enter phone", toast.length_short)                             .show();                 }                 else if (dob.equals("")) {                     invalid = true;                     toast.maketext(getapplicationcontext(),                             "please enter phone", toast.length_short)                             .show();                 }                 else if (father.equals("")) {                     invalid = true;                     toast.maketext(getapplicationcontext(),                             "please enter phone", toast.length_short)                             .show();                 }                 else if (mother.equals("")) {                     invalid = true;                     toast.maketext(getapplicationcontext(),                             "please enter phone", toast.length_short)                             .show();                 }                 else if (username.equals("")) {                     invalid = true;                     toast.maketext(getapplicationcontext(),                             "please enter phone", toast.length_short)                             .show();                 }                 else if (password.equals("")) {                     invalid = true;                     toast.maketext(getapplicationcontext(),                             "please enter phone", toast.length_short)                             .show();                 }                 else if (cpassword.equals("")) {                     invalid = true;                     toast.maketext(getapplicationcontext(),                             "please enter phone", toast.length_short)                             .show();                 }                  else if (invalid == false) {                     addentry(fname, lname, gen, email,phoneno,address,bloodgroup,dob,father,mother,username,password,cpassword);                     intent i_register = new intent(registration.this,mainactivity.class);                     startactivity(i_register);                     // finish();                 }                  break;             }         }          public void ondestroy() {             super.ondestroy();             db.close();         }          private void addentry(string fname, string lname, string gen, string email,string phoneno, string address,string bloodgroup,string dob,string father,string mother,string username,string password,string cpassword) {              sqlitedatabase db = db.getwritabledatabase();              contentvalues values = new contentvalues();             values.put("firstname", fname);             values.put("lastname", lname);             values.put("gender", gen);             values.put("email", email);             values.put("username", phoneno);             values.put("password", address);             values.put("phoneno", bloodgroup);             values.put("lastname", dob);             values.put("gender", father);             values.put("email", mother);             values.put("username", username);             values.put("password", password);             values.put("phoneno", cpassword);              try {                 db.insert(dbhelper.database_table_name, null, values);                  toast.maketext(getapplicationcontext(),                         "your details submitted successfully...",                         toast.length_short).show();             } catch (exception e) {                 e.printstacktrace();             }         }          public void onitemselected(adapterview<?> parent, view view, int position,                 long id) {             // selected state object spinner             state st = (state) mgender.getselecteditem();              // show via toast             toaststate("onitemselected", st);         }          public void toaststate(string name, state st) {             if (st != null) {                 gen = st.name;                 // toast.maketext(getbasecontext(), gen, toast.length_short).show();              }          }          public void onnothingselected(adapterview<?> arg0) {             // todo auto-generated method stub          }  } 

dbhelper.java

package com.example.login1;  import android.content.context; import android.database.cursor; import android.database.sqlexception; import android.database.sqlite.sqlitedatabase; import android.database.sqlite.sqliteopenhelper; import android.widget.edittext; import android.widget.spinner;  public class dbhelper extends sqliteopenhelper {      private sqlitedatabase db;         public static final string key_rowid = "_id";         public static final string key_fname = "firstname";         public static final string key_lname = "lastname";         public static final string key_gender = "gender";         public static final string key_email = "email";         public static final string key_phone = "phoneno";          public static final string key_address = "address";         public static final string key_bloodgroup= "bloodgroup";         public static final string key_dob= "dob";         public static final string key_father= "father";         public static final string key_mother= "mother";         public static final string key_username= "username";         public static final string key_pass= "pass";         public static final string key_cpass= "cpass";          dbhelper db = null;         private static final string database_name = "igate.db";         private static final int database_version = 2;         public static final string database_table_name = "igate1";          private static final string database_table_create = "create table "                 + database_table_name                 + "("                 + "_id integer primary key autoincrement,"                 + "firstname text not null, lastname text not null, gender text not null,email text not null, phoneno text not null, address text not null,bloodgroup text not null, dob text not null,father text not null, mother text not null, username text not null, pass text not null, cpass text not null );";          public dbhelper(context context) {              super(context, database_name, null, database_version);             system.out.println("in constructor");         }          @override         public void oncreate(sqlitedatabase db) {              try {                  db.execsql(database_table_create);              } catch (exception e) {                 e.printstacktrace();             }         }          @override         public void onupgrade(sqlitedatabase db, int oldversion, int newversion) {             // todo auto-generated method stub          }          public cursor rawquery(string string, string[] strings) {             // todo auto-generated method stub             return null;         }          public void open() {              getwritabledatabase();         }          public cursor getdetails(string text) throws sqlexception          {              cursor mcursor = db.query(true, database_table_name, new string[] {                     key_rowid, key_fname, key_lname, key_gender,key_email,key_phone,key_address,key_bloodgroup,                     key_dob,key_father,key_mother,key_username}, key_username + "=" + text, null, null, null, null,                     null);             if (mcursor != null) {                 mcursor.movetofirst();             }             return mcursor;          } } 

state.java

package com.example.login1;  public class state  {      public string name;          public state(string name)         {             this.name = name;         }          public string getname() {             return name;         }          public void setname(string name) {             this.name = name;         }           @override         public string tostring()         {             return name;         } } 

logcat

06-27 02:35:16.910: e/sqlitelog(1393): (1) table igate1 has no column named password 06-27 02:35:16.930: e/sqlitedatabase(1393): error inserting gender=f lastname=f username=f firstname=f password=f email=f phoneno=f 06-27 02:35:16.930: e/sqlitedatabase(1393): android.database.sqlite.sqliteexception: table igate1 has no column named password (code 1): , while compiling: insert igate1(gender,lastname,username,firstname,password,email,phoneno) values (?,?,?,?,?,?,?) 06-27 02:35:16.930: e/sqlitedatabase(1393):     @ android.database.sqlite.sqliteconnection.nativepreparestatement(native method) 06-27 02:35:16.930: e/sqlitedatabase(1393):     @ android.database.sqlite.sqliteconnection.acquirepreparedstatement(sqliteconnection.java:889) 06-27 02:35:16.930: e/sqlitedatabase(1393):     @ android.database.sqlite.sqliteconnection.prepare(sqliteconnection.java:500) 06-27 02:35:16.930: e/sqlitedatabase(1393):     @ android.database.sqlite.sqlitesession.prepare(sqlitesession.java:588) 06-27 02:35:16.930: e/sqlitedatabase(1393):     @ android.database.sqlite.sqliteprogram.<init>(sqliteprogram.java:58) 06-27 02:35:16.930: e/sqlitedatabase(1393):     @ android.database.sqlite.sqlitestatement.<init>(sqlitestatement.java:31) 06-27 02:35:16.930: e/sqlitedatabase(1393):     @ android.database.sqlite.sqlitedatabase.insertwithonconflict(sqlitedatabase.java:1467) 06-27 02:35:16.930: e/sqlitedatabase(1393):     @ android.database.sqlite.sqlitedatabase.insert(sqlitedatabase.java:1339) 06-27 02:35:16.930: e/sqlitedatabase(1393):     @ com.example.login1.registration.addentry(registration.java:215) 06-27 02:35:16.930: e/sqlitedatabase(1393):     @ com.example.login1.registration.onclick(registration.java:180) 06-27 02:35:16.930: e/sqlitedatabase(1393):     @ android.view.view.performclick(view.java:4438) 06-27 02:35:16.930: e/sqlitedatabase(1393):     @ android.view.view$performclick.run(view.java:18422) 06-27 02:35:16.930: e/sqlitedatabase(1393):     @ android.os.handler.handlecallback(handler.java:733) 06-27 02:35:16.930: e/sqlitedatabase(1393):     @ android.os.handler.dispatchmessage(handler.java:95) 06-27 02:35:16.930: e/sqlitedatabase(1393):     @ android.os.looper.loop(looper.java:136) 06-27 02:35:16.930: e/sqlitedatabase(1393):     @ android.app.activitythread.main(activitythread.java:5017) 06-27 02:35:16.930: e/sqlitedatabase(1393):     @ java.lang.reflect.method.invokenative(native method) 06-27 02:35:16.930: e/sqlitedatabase(1393):     @ java.lang.reflect.method.invoke(method.java:515) 06-27 02:35:16.930: e/sqlitedatabase(1393):     @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:779) 06-27 02:35:16.930: e/sqlitedatabase(1393):     @ com.android.internal.os.zygoteinit.main(zygoteinit.java:595) 06-27 02:35:16.930: e/sqlitedatabase(1393):     @ dalvik.system.nativestart.main(native method) 

please help......

i have tried whatever suggestions give...but m getting error

logcat(my 2nd logcat)

06-27 04:23:42.960: e/androidruntime(1581): fatal exception: main 06-27 04:23:42.960: e/androidruntime(1581): process: com.example.login1, pid: 1581 06-27 04:23:42.960: e/androidruntime(1581): java.lang.nullpointerexception 06-27 04:23:42.960: e/androidruntime(1581):     @ com.example.login1.mainactivity.validatelogin(mainactivity.java:113) 06-27 04:23:42.960: e/androidruntime(1581):     @ com.example.login1.mainactivity.onclick(mainactivity.java:71) 06-27 04:23:42.960: e/androidruntime(1581):     @ android.view.view.performclick(view.java:4438) 06-27 04:23:42.960: e/androidruntime(1581):     @ android.view.view$performclick.run(view.java:18422) 06-27 04:23:42.960: e/androidruntime(1581):     @ android.os.handler.handlecallback(handler.java:733) 06-27 04:23:42.960: e/androidruntime(1581):     @ android.os.handler.dispatchmessage(handler.java:95) 06-27 04:23:42.960: e/androidruntime(1581):     @ android.os.looper.loop(looper.java:136) 06-27 04:23:42.960: e/androidruntime(1581):     @ android.app.activitythread.main(activitythread.java:5017) 06-27 04:23:42.960: e/androidruntime(1581):     @ java.lang.reflect.method.invokenative(native method) 06-27 04:23:42.960: e/androidruntime(1581):     @ java.lang.reflect.method.invoke(method.java:515) 06-27 04:23:42.960: e/androidruntime(1581):     @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:779) 06-27 04:23:42.960: e/androidruntime(1581):     @ com.android.internal.os.zygoteinit.main(zygoteinit.java:595) 06-27 04:23:42.960: e/androidruntime(1581):     @ dalvik.system.nativestart.main(native method) 

error says clearly: table igate1 has no column named password.

your create query is:

private static final string database_table_create = "create table "                 + database_table_name                 + "("                 + "_id integer primary key autoincrement,"                 + "firstname text not null, lastname text not null, gender text not null,email text not null, phoneno text not null, address text not null,bloodgroup text not null, dob text not null,father text not null, mother text not null, username text not null, pass text not null, cpass text not null );"; 

and there fields pass , cpass, not password.

change that, , you're done.

hope helps.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -