java - error in insertdata database -
please me problem now, in activities there 2 errors , first in insertdata
@override public void onclick(view arg0) { db.open(); db.insertdata(editnama.gettext().tostring()), cekpria.ischecked(), cekwanita.ischecked(), edittanggal.gettext().tostring(); db.close(); toast.maketext(getbasecontext(),"data telah disimpan", toast.length_short).show(); editnama.settext(""); cekpria.setchecked(false); cekwanita.setchecked(false); edittanggal.settext(""); } });
and second error in "variable 'kelamin' might not have been initialized". give sign // place error
public void tampilkandata(){ db.open(); cursor c =db.getalldata(); arraylist<string> larik = new arraylist<string>(); if (c.movetofirst()){ { int idartis = c.getint(0); string namaartis = c.getstring(1); int genderpria = c.getint(2); int genderwanita = c.getint(3); string tglahir = c.getstring(4); string kelamin; if (genderpria == 1){ kelamin = "pria"; }else if (genderwanita == 1){ kelamin = "wanita"; }else{ toast.maketext(getapplicationcontext(), "isi salah satu", toast.length_short).show(); } //larik.add(integer.tostring(idartis) + ": " + namaartis + " (" + kelamin + ") -" + tglahir); }while (c.movetonext()); } db.close(); arrayadapter<string> adapter = new arrayadapter<string>(this, android.r.layout.simple_list_item_1, larik); listviewdata.setadapter(adapter); }
this code insertdata()
public long insertdata(string nama, boolean gender, string tanggal){ try { contentvalues databaru = new contentvalues(); databaru.put(konstanta.nama_artis, nama); databaru.put(konstanta.gender_artis_pria, gender); databaru.put(konstanta.gender_artis_wanita, gender); databaru.put(konstanta.tglahir, tanggal); return db.insert(konstanta.nama_tabel, null, databaru); }catch (sqliteexception e){ return -1; } }
error 1:
this statement wrong. should end ;
. also, looks misplaced brackets )
.
db.insertdata(editnama.gettext().tostring()), cekpria.ischecked(), cekwanita.ischecked(),
wild guess: should be
db.insertdata(editnama.gettext().tostring(), cekpria.ischecked(), cekwanita.ischecked());
if post code of insertdata
, can better.
error 2
change
string kelamin;
with
string kelamin = null;
or string kelamin = "";
per needs
Comments
Post a Comment