objective c - EXC_BAD_ACCESS (code = 2, adress = 0x0) while changing value of boolean -
what i'm trying do
in app, got sql-lite database wrote methodes. callback of method boolean. true = write data, false = not write data. code dosn't show error's in x-code should right.
question
in method define boolean , set null. afterwards have if-clause, check's if data written db, , change defined boolean true or false. throws me error:exc_bad_access (code = 2, address = 0x0)
the point is, don't understand why error coming along. guys please tell me, i'm doing wrong , how can solve it. you'll find code down here:
code
- (bool *) createlogin:(nsinteger *)user_id usr: (nsstring *)username pwd: (nsstring *)password date: (nsdate *)last_login{ bool *returnvalue = null; self.ivo_db = [[ivo_database alloc] init]; if((sqlite3_open_v2([[ivo_db getwritabledatabase] utf8string], &sqldb, sqlite_open_readwrite, null) != sqlite_ok)){ nslog(@" %s couldn't open writable database '%s' (%1d)", __function__, sqlite3_errmsg(sqldb), sqlite3_errcode(sqldb)); }else{ int userid = *user_id; nsstring *sqlstring = [nsstring stringwithformat:@"insert tbl_login (user_id, username, password, last_login) values (%d,'%@','%@','%@')", userid, username, password, last_login]; const char *putlogindata = [sqlstring utf8string]; sqlite3_stmt *sqlstatement; if(sqlite3_prepare(sqldb, putlogindata, -1, &sqlstatement, null) != sqlite_ok) { nslog(@"%s sqlite_error while preparing statement '%s' (%1d)", __function__, sqlite3_errmsg(sqldb), sqlite3_errcode(sqldb)); *returnvalue = no; }else{ sqlite3_step(sqlstatement); sqlite3_finalize(sqlstatement); int lastinsert = sqlite3_last_insert_rowid(sqldb); nslog(@"lastinsertid:%d", lastinsert); sqlite3_close(sqldb); *returnvalue = yes; } } return returnvalue; }
bool *returnvalue = null; /* ... */ *returnvalue = yes;
you first create pointer bool. set address it's pointing to null. try set value of address it's pointing to yes.
or short: try write @ adress 0x00. won't work.
you want use bool. primitive type, without pointer.
- (bool) createlogin:(nsinteger *)user_id usr: (nsstring *)username pwd: (nsstring *)password date: (nsdate *)last_login{ bool returnvalue = no; /* ... */ returnvalue = yes; /* ... */ return returnvalue; }
Comments
Post a Comment