android - Application crashes when program goes from one activity to another -


i try launch application menuactivity recipesactivity. in recipesactivity try select elements table, create in database class (database.java). table empty. debugger can't me, don't know why application crashes, maybe because tables empty now.

part of menuactivity.java

    case r.id.recipes:     case r.id.iconrecipes:         intent i2 = new intent(this, recipesactivity.class);         this.startactivity(i2);         break; 

part of recipesactivity.java

public class recipesactivity extends activity implements onclicklistener {  static final public int addingrecipe = 0; static final public int editingrecipe = 1; //static final public string editrecipe = "editrecipe"; static final public string recipeid = "recipeid"; static final public string showrecipe = "showrecipe"; linearlayout ll; database sqh; sqlitedatabase sqdb;  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_recipes);  ll = (linearlayout)findviewbyid(r.id.llrecipes);  sqh = new database(this);  sqdb = sqh.getwritabledatabase();         cursor cursor = sqdb.rawquery("select _id, name, doctor disease", null);  while (cursor.movetonext()) {      linearlayout ll2 = new linearlayout(this);     ll2.setorientation(linearlayout.horizontal);     final textview tv = new textview(this);     tv.setid(cursor.getint(cursor.getcolumnindex("_id")));     tv.setlayoutparams(new layoutparams(layoutparams.wrap_content, layoutparams.wrap_content));     string disease = cursor.getstring(cursor.getcolumnindex("name"));     string doctor = cursor.getstring(cursor.getcolumnindex("doctor"));     tv.settext(disease +"\nВрач: "+ doctor);     ll2.addview(tv);     imagebutton edit = new imagebutton(this);     edit.setid(cursor.getint(cursor.getcolumnindex("_id")));     edit.setclickable(true);     edit.setonclicklistener(new onclicklistener() {         @override         public void onclick(view v) {             // todo auto-generated method stub             //textview tv2 = tv;             intent i3 = new intent(recipesactivity.this, addeditrecipesactivity.class);             i3.addflags(editingrecipe);             i3.putextra(recipeid, v.getid());             //i3.putextra(editrecipe, tv2.gettext().tostring());             //startactivityforresult(i3, editingrecipe);             startactivity(i3);         }     });     edit.setbackgroundresource(r.drawable.edit);     ll2.addview(edit);     imagebutton go = new imagebutton(this);     go.setid(cursor.getint(cursor.getcolumnindex("_id")));     go.setclickable(true);     go.setbackgroundresource(r.drawable.go);     go.setonclicklistener(new onclicklistener() {         @override         public void onclick(view v) {             intent i3 = new intent(recipesactivity.this, medicineactivity.class);             i3.putextra(showrecipe, v.getid());             recipesactivity.this.startactivity(i3);         }     });     ll2.addview(go);     ll.addview(ll2); }  }     } 

thanks.

check cursor object not null , go inside...

if(cursor !=null){ while (cursor.movetonext()) { . . . } } 

Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -