android - Button for Submitting to Database Error -


i want insert data row in sqlite database table filling form , has error when click submit button. here's piece of code , logcat

public void calldialogconfirmation(){      alertdialog.builder confirm = new alertdialog.builder(form.this);       confirm.settitle("please confirm");        confirm.setpositivebutton("yes",         new dialoginterface.onclicklistener() {          public void onclick(dialoginterface dialog, int id) {                 string inputansavings = spinner1.getselecteditem().tostring();             string tglmsk = spinner2.getselecteditem().tostring();              sharedpreferences.editor editor = somedata.edit();             editor.putstring("sharedstring1", inputansavings);             editor.putstring("sharedstring2", tglmsk);              editor.commit();              string inputsalary = salary.gettext().tostring();              dbhelper.createincome("routine income",inputsalary);                       intent openstartingpoint = new intent(form.this, mainactivity.class);             startactivity(openstartingpoint);            }}); 

and here's method insert data

       public long createincome(string l, string n) {       contentvalues initialvalues = new contentvalues();     initialvalues.put(rlpe, l);     initialvalues.put(rnpe, n);     initialvalues.put(rbpe, m);   // m current date calendar library      return mdbp.insert(income_table, null, initialvalues);  } 

here's error i'm getting click "submit" button

            07-21 22:00:39.234: e/androidruntime(971): fatal exception: main             07-21 22:00:39.234: e/androidruntime(971): java.lang.nullpointerexception             07-21 22:00:39.234: e/androidruntime(971):  @     com.diarykeuanganmahasiswa.dkm.form$1.onclick(form.java:64)             07-21 22:00:39.234: e/androidruntime(971):  @ com.android.internal.app.alertcontroller$buttonhandler.handlemessage(alertcontroller.java:159)             07-21 22:00:39.234: e/androidruntime(971):  @ android.os.handler.dispatchmessage(handler.java:99)             07-21 22:00:39.234: e/androidruntime(971):  @ android.os.looper.loop(looper.java:123)             07-21 22:00:39.234: e/androidruntime(971):  @ android.app.activitythread.main(activitythread.java:3683)            07-21 22:00:39.234: e/androidruntime(971):   @ java.lang.reflect.method.invokenative(native method)            07-21 22:00:39.234: e/androidruntime(971):   @ java.lang.reflect.method.invoke(method.java:507)            07-21 22:00:39.234: e/androidruntime(971):   @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:839)           07-21 22:00:39.234: e/androidruntime(971):    @ com.android.internal.os.zygoteinit.main(zygoteinit.java:597)           07-21 22:00:39.234: e/androidruntime(971):    @ dalvik.system.nativestart.main(native method) 

anyone knows seems problem? please help, thanks

it looks your storing data ui in shared preferences , attempting retrieve them contentvalues. in ui should put values content values , pass insert. retrieval of value in insert method should able them properly. content values name value pair, i.e. name of column , value of column.

in ui activity:

contentvalues cv; ... //in onclick method cv = new contentvalues(); ... cv.put("inputansavings", inputansavings); ... etc, each column. 

uri rowuri = cr.insert(youruri, cv); // cv should have nvp (name value pair) each of columns.

if needed can put content values bundle , have async task or content provider extract them, if have lot of other steps accomplish before insert.

hope helps. please mark correct answer if works you.

have great day.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -