java - Getting an error while creating new instance SQLITE -
i have error while making creating new instance writing data database sqllite
this code of database class
package com.example.tttt; import android.content.contentvalues; import android.content.context; import android.database.cursor; import android.database.sqlexception; import android.database.sqlite.sqlitedatabase; import android.database.sqlite.sqliteopenhelper; public class info { public static final string key_nom = "nom_personne"; public static final string key_id = "id_personne"; public static final string key_prenom = "prenom_personne"; private static final string database_name = "infodb"; private static final string database_table = "infotable"; private static final int database_version = 1 ; private dbhelper ourhelper; private context ourcontext ; private sqlitedatabase ourdatabase ; private static class dbhelper extends sqliteopenhelper { public dbhelper(context context) { super(context, database_name,null , database_version ); // todo auto-generated constructor stub } @override public void oncreate(sqlitedatabase db) { // todo auto-generated method stub db.execsql( "create table " + database_table + " (" + key_id + " integer primary key autoincrement, " + key_nom + " text not null, " + key_prenom + " text not null);" ); } @override public void onupgrade(sqlitedatabase db, int arg1, int arg2) { // todo auto-generated method stub db.execsql("drop table if exists " + database_table); oncreate(db); } } public info open() throws sqlexception{ ourhelper = new dbhelper(ourcontext); ourdatabase = ourhelper.getwritabledatabase(); return this; } public void close(){ ourhelper.close(); } public long createentry(string name, string prenom) { // todo auto-generated method stub contentvalues cv = new contentvalues(); cv.put(key_nom, name); cv.put(key_prenom, prenom); return ourdatabase.insert(database_table, null, cv); }
in class activity wrote
info entry = new info(this); entry.open(); entry.createentry(name , prenom ); entry.close();
i had error on info entry = new info(this);
message error : " constructor info(new view.onclicklistener(){}) undefined "
when change info entry = new info(intro.this);
i got: "the constructor info(intro) undefined"
the full intro activity try information user , send them database
package com.example.tttt; import com.example.tttt.r.layout; import android.app.activity; import android.app.dialog; import android.content.intent; import android.os.bundle; import android.os.dropboxmanager.entry; import android.view.view; import android.view.view.onclicklistener; import android.view.viewgroup.layoutparams; import android.widget.button; import android.widget.edittext; import android.widget.textview; public class intro extends activity { button sqlupdate,sqlview,sqlsearch; edittext sqlnom, sqlprenom,sqltextsearch ; @override protected void oncreate(bundle savedinstancestate) { // todo auto-generated method stub super.oncreate(savedinstancestate); setcontentview(r.layout.intro); sqlnom = (edittext)findviewbyid(r.id.nomenter); sqlprenom = (edittext)findviewbyid(r.id.prenomenter); sqlupdate = (button) findviewbyid(r.id.button1); sqlview = (button) findviewbyid(r.id.button2); // sqlsearch = (button) findviewbyid(r.id.button3); // sqltextsearch = (edittext)findviewbyid(r.id.edittext1); sqlupdate.setonclicklistener(new view.onclicklistener() { @override public void onclick(view arg0) { // todo auto-generated method stub boolean diditwork = true ; try{ string name = sqlnom.gettext().tostring(); string prenom = sqlprenom.gettext().tostring(); entry = new info(); entry.open(); entry.createentry(name , prenom ); entry.close(); }catch (exception e ){ diditwork = false ; string error = e.tostring(); dialog d = new dialog(intro.this); d.settitle(" merde "); textview tv = new textview(intro.this); tv.settext(error); d.setcontentview(tv); d.show(); }finally{ if (diditwork){ dialog d = new dialog(intro.this); d.settitle(" okkk "); textview tv = new textview(intro.this); tv.settext(" ok yes "); d.setcontentview(tv); d.show(); } } } }); sqlview.setonclicklistener(new view.onclicklistener() { @override public void onclick(view arg0) { // todo auto-generated method stub intent open = new intent("android.intent.action.sqlview"); startactivity(open); } }); sqlsearch.setonclicklistener(new view.onclicklistener() { @override public void onclick(view arg0) { // todo auto-generated method stub /*string s = sqltextsearch.gettext().tostring(); info se = new info(); se.open(); string returne = se.search(); */ } }); } }
you have initialize info class without parameters:
info entry = new info();
btw. common in class names write first letter uppercase: info
furthermore. if dont have more code in info
application throw nullpointerexception
here ourdatabase.insert(database_table, null, cv);
Comments
Post a Comment