database - Android SQLite - not able to create Table -


this question has answer here:

this extraction of mainactivity in want create database table

public class gamedrive extends activity {   databasehelper databasehelper; sqlitedatabase database;    @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_game_drive);     getactionbar().setdisplayhomeasupenabled(true);       databasehelper = new databasehelper(this);     database  = databasehelper.getwritabledatabase(); 

. . .

public class databasehelper extends sqliteopenhelper {  private static final string databse_name = "database"; private static final string table_name = "tripdata"; private static final string column_id = "_id"; private static final string column_typ = "typ"; private static final string column_value = "value";  private static final int database_version = 1;     public databasehelper(context context){     super(context, databse_name, null, database_version);     log.d("database","constructor called");  }   //database created first time. creation of table , initial data inside done here @override public void oncreate(sqlitedatabase db) {     log.d("database","oncreate called");      db.execsql("create table "+table_name+"("+column_id+" integer primary key autoincrement, "+column_typ+" varchar(255),"+column_value+" varchar(255));" );      log.d("database","oncreate called succesfuly");  }  //drop tables, add tables etc. @override public void onupgrade(sqlitedatabase db, int oldversion, int newversion) {     // todo auto-generated method stub     try {         db.execsql("drop table if exists table_name");         oncreate(db);     } catch (sqlexception e) {         // todo auto-generated catch block         e.printstacktrace();     } } 

}

why log.d("database","oncreate called") never reached? after starting app log.d("database","constructor called") statement reached.

thank you!

i'm guessing table there. ondreate not executed again. try installing sqlite viewer better visualize db. cannot see method getwritabledatabase() in databasehelper. please check on this.

another thing try modify create table command create table if not exists.


Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -