java - validate username unique getting error -


i want verify username exist or not, code shown below, put code in protected void oncreate(bundle savedinstancestate){//put code inside here, correct?}

public boolean verification(string _username) {         cursor c = db.rawquery( "select count(*) " + "login" + " " + "username" + " = ?", new string[] {_username});         boolean exists = c.movetofirst();         c.close();         return exists;     } 

and want check when user click register button, put code shown below in public void onclick(view v) {//put code inside here, correct?}

// check if user exists?                      if(verification(username) == true){                 toast.maketext(getapplicationcontext(), "username exists", toast.length_long).show();                 return;                 } 

when run application click register button, apps force close. logcat shown: logcat errors

any idea? or how make sure username unique? sorry i'm still newbie.

edit problem solved when code below:

if(logindatabaseadapter.verification(username) == false){                 toast.maketext(getapplicationcontext(), "username exists", toast.length_long).show();                 return;                 } 

but can't verify user neither put true or false, idea?

this npe case, causing line 87. have mentioned above line 87

cursor c = db.rawquery( "select count(*) " + "login" + " " + "username" + " = ?", new string[] {_username}); 

so exception occurring because trying operate on reference null. , here variable db.

you should put null check before performing query:

if(null == db){ // initialize db } 

also, following link may know database in android http://www.vogella.com/articles/androidsqlite/article.html


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -