java - NullPointerException when saving into a database -
im trying save strings are: category, title, body database, i'm getting nullpointerexception whenever try execute savestate()
method. me ?
//exectued when press save button public void onclicksave(view v) { savestate(); } // fire creation private void savestate() { string title = mjoketitle.gettext().tostring(); string body = mjokebody.gettext().tostring(); long id = mdbhelper.createjoke(enteredcat, title, body); }
my database schema
public class notesdbadapter { public static final string key_title = "title"; public static final string key_body = "body"; public static final string key_category = "category"; public static final string key_row_id = "_id"; private static final string tag = "notesdbadapter"; private databasehelper mdbhelper; private sqlitedatabase mdb; private static final string database_name = "my_database"; private static final string database_table = "jokes"; private static final int database_version = 3; private static final string database_create = "create table " + database_table + " (_id integer primary key autoincrement, " + "title text not null, body text not null, category text not null unique);"; public long createjoke(string category, string title, string body) { contentvalues initialvalues = new contentvalues(); initialvalues.put(key_category, category); initialvalues.put(key_title, title); initialvalues.put(key_body, body); // return rowid if successful, otherwise -1 return mdb.insert(database_table, null, initialvalues); }
private void savestate() { string title =""; string body=""; if(mjoketitle.gettext()!=nll){ title = mjoketitle.gettext().tostring(); }else{ system.out.println("mjoketitle.gettext() value null need why value null"); } if( mjokebody.gettext()!=nll){ body = mjokebody.gettext().tostring(); }else{ system.out.println(" mjokebody.gettext() value null need why value null"); } if(mdbhelper!=null){ long id = mdbhelper.createjoke(enteredcat, title, body); }else{ system.out.println("mdbhelper value null need why value null"); }
}
Comments
Post a Comment