Android errors when using code from stackoverflow to implement sqlite database -



Android errors when using code from stackoverflow to implement sqlite database -

i error: class "databasehelper" must either abstract or implement abstract method.

when running code found , stackoverflow, got code: how utilize own database - android

it's first part errors, sec part working fine.

code:

import java.io.file; import java.io.fileoutputstream; import java.io.ioexception; import java.io.inputstream; import java.io.outputstream; import android.content.context; import android.database.sqlexception; import android.database.sqlite.sqlitedatabase; import android.database.sqlite.sqliteopenhelper; import android.util.log; public class databasehelper extends sqliteopenhelper { private static string tag = "databasehelper"; // tag logcat window //destination path (location) of our database on device private static string db_path = ""; private static string db_name ="menustat.db.sqlite";// database name private sqlitedatabase mdatabase; private final context mcontext; public databasehelper(context context) { super(context, db_name, null, 1);// 1? database version if(android.os.build.version.sdk_int >= 17){ db_path = context.getapplicationinfo().datadir + "/databases/"; } else { db_path = "/data/data/" + context.getpackagename() + "/databases/"; } this.mcontext = context; } public void createdatabase() throws ioexception { //if database not exists re-create assets boolean mdatabaseexist = checkdatabase(); if(!mdatabaseexist) { this.getreadabledatabase(); this.close(); seek { //copy database assests copydatabase(); log.e(tag, "createdatabase database created"); } grab (ioexception mioexception) { throw new error("errorcopyingdatabase"); } } } //check database exists here: /data/data/your package/databases/da name private boolean checkdatabase() { file dbfile = new file(db_path + db_name); //log.v("dbfile", dbfile + " "+ dbfile.exists()); homecoming dbfile.exists(); } //copy database assets private void copydatabase() throws ioexception { inputstream minput = mcontext.getassets().open(db_name); string outfilename = db_path + db_name; outputstream moutput = new fileoutputstream(outfilename); byte[] mbuffer = new byte[1024]; int mlength; while ((mlength = minput.read(mbuffer))>0) { moutput.write(mbuffer, 0, mlength); } moutput.flush(); moutput.close(); minput.close(); } //open database, can query public boolean opendatabase() throws sqlexception { string mpath = db_path + db_name; //log.v("mpath", mpath); mdatabase = sqlitedatabase.opendatabase(mpath, null, sqlitedatabase.create_if_necessary); //mdatabase = sqlitedatabase.opendatabase(mpath, null, sqlitedatabase.no_localized_collators); homecoming mdatabase != null; } @override public synchronized void close() { if(mdatabase != null) mdatabase.close(); super.close(); } }

you need implement abstract methods onupgrade , oncreate:

public class databasehelper extends sqliteopenhelper { // ... @override public void oncreate(sqlitedatabase db) { } @override public void onupgrade(sqlitedatabase db, int oldversion, int newversion) { } }

see sqliteopenhelper documentation.

android sqlite

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -