java - My Android app crashes when trying to store SQLite data -


i tried import sqlite sample code android application save , manage data through sqlite, using listview.

in sqlite sample implements addressbook when fill in text fields of new contact , press "save" button save them sqlite, android app crashes, displaying unfortunately application has terminated.i believe problem focused on button save(button1) , line: android:onclick="run" don't understand exact problem.for convenience method "run" implemented in displaycontact.java archive.

the code of button1 in activity_display_contact.xml layout is:

<button       android:id="@+id/button1"       android:layout_width="wrap_content"       android:layout_height="wrap_content"       android:layout_alignleft="@+id/edittextcity"       android:layout_alignparentbottom="true"       android:layout_marginbottom="28dp"       android:onclick="run"       android:text="@string/save" /> 

the code of displaycontact.java responsible tha layout of listview :

package com.qualcomm.qcarsamples.imagetargets;  import com.qualcomm.qcarsamples.imagetargets1.r;  import android.os.bundle; import android.app.activity; import android.app.alertdialog; import android.content.dialoginterface; import android.content.intent; import android.database.cursor; import android.view.menu; import android.view.menuitem; import android.view.view; import android.widget.button; import android.widget.textview; import android.widget.toast;  public class displaycontact extends activity {     int from_where_i_am_coming = 0;    private dbhelper mydb ;    textview name ;    textview phone;    textview email;    textview street;    textview place;    int id_to_update = 0;      @override    protected void oncreate(bundle savedinstancestate) {       super.oncreate(savedinstancestate);       setcontentview(r.layout.activity_display_contact);       name = (textview) findviewbyid(r.id.edittextname);       phone = (textview) findviewbyid(r.id.edittextphone);       email = (textview) findviewbyid(r.id.edittextstreet);       street = (textview) findviewbyid(r.id.edittextemail);       place = (textview) findviewbyid(r.id.edittextcity);        mydb = new dbhelper(this);        bundle extras = getintent().getextras();        if(extras !=null)       {          int value = extras.getint("id");          if(value>0){             //means view part not add contact part.             cursor rs = mydb.getdata(value);             id_to_update = value;             rs.movetofirst();             string nam = rs.getstring(rs.getcolumnindex(dbhelper.contacts_column_name));             string phon = rs.getstring(rs.getcolumnindex(dbhelper.contacts_column_phone));             string emai = rs.getstring(rs.getcolumnindex(dbhelper.contacts_column_email));             string stree = rs.getstring(rs.getcolumnindex(dbhelper.contacts_column_street));             string plac = rs.getstring(rs.getcolumnindex(dbhelper.contacts_column_city));             if (!rs.isclosed())              {                rs.close();             }             button b = (button)findviewbyid(r.id.button1);             b.setvisibility(view.invisible);              name.settext((charsequence)nam);             name.setfocusable(false);             name.setclickable(false);              phone.settext((charsequence)phon);             phone.setfocusable(false);              phone.setclickable(false);              email.settext((charsequence)emai);             email.setfocusable(false);             email.setclickable(false);              street.settext((charsequence)stree);             street.setfocusable(false);              street.setclickable(false);              place.settext((charsequence)plac);             place.setfocusable(false);             place.setclickable(false);            }       }    }    @override    public boolean oncreateoptionsmenu(menu menu) {       // inflate menu; adds items action bar if present.       bundle extras = getintent().getextras();        if(extras !=null)       {          int value = extras.getint("id");          if(value>0){             getmenuinflater().inflate(r.menu.display_contact, menu);          }          else{             getmenuinflater().inflate(r.menu.mainmenu, menu);          }       }       return true;    }     public boolean onoptionsitemselected(menuitem item)     {        super.onoptionsitemselected(item);        switch(item.getitemid())     {        case r.id.edit_contact:        button b = (button)findviewbyid(r.id.button1);       b.setvisibility(view.visible);       name.setenabled(true);       name.setfocusableintouchmode(true);       name.setclickable(true);        phone.setenabled(true);       phone.setfocusableintouchmode(true);       phone.setclickable(true);        email.setenabled(true);       email.setfocusableintouchmode(true);       email.setclickable(true);        street.setenabled(true);       street.setfocusableintouchmode(true);       street.setclickable(true);        place.setenabled(true);       place.setfocusableintouchmode(true);       place.setclickable(true);        return true;        case r.id.delete_contact:        alertdialog.builder builder = new alertdialog.builder(this);       builder.setmessage(r.string.deletecontact)      .setpositivebutton(r.string.yes, new dialoginterface.onclicklistener() {          public void onclick(dialoginterface dialog, int id) {             mydb.deletecontact(id_to_update);             toast.maketext(getapplicationcontext(), "deleted successfully", toast.length_short).show();               intent intent = new intent(getapplicationcontext(),com.qualcomm.qcarsamples.imagetargets.mainactivity.class);             startactivity(intent);          }       })      .setnegativebutton(r.string.no, new dialoginterface.onclicklistener() {          public void onclick(dialoginterface dialog, int id) {             // user cancelled dialog          }       });       alertdialog d = builder.create();       d.settitle("are sure");       d.show();        return true;       default:        return super.onoptionsitemselected(item);         }     }      public void run(view view)    {           bundle extras = getintent().getextras();       if(extras !=null)       {          int value = extras.getint("id");          if(value>0){             if(mydb.updatecontact(id_to_update,name.gettext().tostring(), phone.gettext().tostring(), email.gettext().tostring(), street.gettext().tostring(), place.gettext().tostring())){                toast.maketext(getapplicationcontext(), "updated", toast.length_short).show();                   intent intent = new intent(getapplicationcontext(),com.qualcomm.qcarsamples.imagetargets.mainactivity.class);                startactivity(intent);              }                   else{                toast.maketext(getapplicationcontext(), "not updated", toast.length_short).show();                }          }          else{             if(mydb.insertcontact(name.gettext().tostring(), phone.gettext().tostring(), email.gettext().tostring(), street.gettext().tostring(), place.gettext().tostring())){                toast.maketext(getapplicationcontext(), "done", toast.length_short).show();               }                    else{                toast.maketext(getapplicationcontext(), "not done", toast.length_short).show();               }             intent intent = new intent(getapplicationcontext(),com.qualcomm.qcarsamples.imagetargets.mainactivity.class);             startactivity(intent);             }       }    } } 

and code of logcat following:

04-07 04:09:25.113: e/androidruntime(7943): fatal exception: main 04-07 04:09:25.113: e/androidruntime(7943): java.lang.illegalstateexception: not find method run(view) in activity class com.qualcomm.qcarsamples.imagetargets.imagetargets onclick handler on view class android.widget.button id 'button1' 04-07 04:09:25.113: e/androidruntime(7943):     @ android.view.view$1.onclick(view.java:3050) 04-07 04:09:25.113: e/androidruntime(7943):     @ android.view.view.performclick(view.java:3534) 04-07 04:09:25.113: e/androidruntime(7943):     @ android.view.view$performclick.run(view.java:14263) 04-07 04:09:25.113: e/androidruntime(7943):     @ android.os.handler.handlecallback(handler.java:605) 04-07 04:09:25.113: e/androidruntime(7943):     @ android.os.handler.dispatchmessage(handler.java:92) 04-07 04:09:25.113: e/androidruntime(7943):     @ android.os.looper.loop(looper.java:137) 04-07 04:09:25.113: e/androidruntime(7943):     @ android.app.activitythread.main(activitythread.java:4441) 04-07 04:09:25.113: e/androidruntime(7943):     @ java.lang.reflect.method.invokenative(native method) 04-07 04:09:25.113: e/androidruntime(7943):     @ java.lang.reflect.method.invoke(method.java:511) 04-07 04:09:25.113: e/androidruntime(7943):     @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:784) 04-07 04:09:25.113: e/androidruntime(7943):     @ com.android.internal.os.zygoteinit.main(zygoteinit.java:551) 04-07 04:09:25.113: e/androidruntime(7943):     @ dalvik.system.nativestart.main(native method) 04-07 04:09:25.113: e/androidruntime(7943): caused by: java.lang.nosuchmethodexception: run [class android.view.view] 04-07 04:09:25.113: e/androidruntime(7943):     @ java.lang.class.getconstructorormethod(class.java:460) 04-07 04:09:25.113: e/androidruntime(7943):     @ java.lang.class.getmethod(class.java:915) 04-07 04:09:25.113: e/androidruntime(7943):     @ android.view.view$1.onclick(view.java:3043) 04-07 04:09:25.113: e/androidruntime(7943):     ... 11 more 

this weird: java code creates activity called "displaycontact" stacktrace says cannot find onclick handler called "run" in activity called "imagetargets". check way development project has been set up.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -