title: insert initial data to sql lite android
body: <p>I'm developing an expense tracker where I want to populate the DB with a few records when the application first start. I tried to call the method in my splash activity and add the data.! But when I clear my application data and start the application for the first time an error occurs saying that there is no such column.</p>
  
  <p>The log cat error is as shown below.</p>
  
  <pre><code>06-30 18:09:58.834: E/SQLiteLog(18380): (1) no such column: exp_type
  06-30 18:10:00.826: D/AndroidRuntime(18380): Shutting down VM
  06-30 18:10:00.826: W/dalvikvm(18380): threadid=1: thread exiting with uncaught exception (group=0x416b8318)
  06-30 18:10:00.856: E/AndroidRuntime(18380): FATAL EXCEPTION: main
  06-30 18:10:00.856: E/AndroidRuntime(18380): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.sliit.expenseanalyzer/com.sliit.expenseanalyzer.SplashActivity}: android.database.sqlite.SQLiteException: no such column: exp_type (code 1): , while compiling: SELECT * FROM expense_type Order BY exp_type DESC
  06-30 18:10:00.856: E/AndroidRuntime(18380):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2063)
  06-30 18:10:00.856: E/AndroidRuntime(18380):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2088)
  06-30 18:10:00.856: E/AndroidRuntime(18380):    at android.app.ActivityThread.access$600(ActivityThread.java:134)
  06-30 18:10:00.856: E/AndroidRuntime(18380):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1199)
  06-30 18:10:00.856: E/AndroidRuntime(18380):    at android.os.Handler.dispatchMessage(Handler.java:99)
  06-30 18:10:00.856: E/AndroidRuntime(18380):    at android.os.Looper.loop(Looper.java:137)
  06-30 18:10:00.856: E/AndroidRuntime(18380):    at android.app.ActivityThread.main(ActivityThread.java:4744)
  06-30 18:10:00.856: E/AndroidRuntime(18380):    at java.lang.reflect.Method.invokeNative(Native Method)
  06-30 18:10:00.856: E/AndroidRuntime(18380):    at java.lang.reflect.Method.invoke(Method.java:511)
  06-30 18:10:00.856: E/AndroidRuntime(18380):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
  06-30 18:10:00.856: E/AndroidRuntime(18380):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
  06-30 18:10:00.856: E/AndroidRuntime(18380):    at dalvik.system.NativeStart.main(Native Method)
  06-30 18:10:00.856: E/AndroidRuntime(18380): Caused by: android.database.sqlite.SQLiteException: no such column: exp_type (code 1): , while compiling: SELECT * FROM expense_type Order BY exp_type DESC
  06-30 18:10:00.856: E/AndroidRuntime(18380):    at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
  06-30 18:10:00.856: E/AndroidRuntime(18380):    at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:882)
  06-30 18:10:00.856: E/AndroidRuntime(18380):    at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:493)
  06-30 18:10:00.856: E/AndroidRuntime(18380):    at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
  06-30 18:10:00.856: E/AndroidRuntime(18380):    at android.database.sqlite.SQLiteProgram.&lt;init&gt;(SQLiteProgram.java:58)
  06-30 18:10:00.856: E/AndroidRuntime(18380):    at android.database.sqlite.SQLiteQuery.&lt;init&gt;(SQLiteQuery.java:37)
  06-30 18:10:00.856: E/AndroidRuntime(18380):    at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
  06-30 18:10:00.856: E/AndroidRuntime(18380):    at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1314)
  06-30 18:10:00.856: E/AndroidRuntime(18380):    at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1161)
  06-30 18:10:00.856: E/AndroidRuntime(18380):    at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1032)
  06-30 18:10:00.856: E/AndroidRuntime(18380):    at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1200)
  06-30 18:10:00.856: E/AndroidRuntime(18380):    at com.sliit.expenseanalyzer.util.DatabaseHandler.getAllExpenseTypes(DatabaseHandler.java:218)
  06-30 18:10:00.856: E/AndroidRuntime(18380):    at com.sliit.expenseanalyzer.SplashActivity.onCreate(SplashActivity.java:29)
  06-30 18:10:00.856: E/AndroidRuntime(18380):    at android.app.Activity.performCreate(Activity.java:5008)
  06-30 18:10:00.856: E/AndroidRuntime(18380):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
  06-30 18:10:00.856: E/AndroidRuntime(18380):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2027)
  06-30 18:10:00.856: E/AndroidRuntime(18380):    ... 11 more
  </code></pre>
  
  <p>How can I populate the data when the application starts for the first time! It's only few records so I'm not worried about performance.</p>
  
  <p>It would be a great help! </p>
  
  <p>Thank you.</p>
  
  <p><strong>DATABASE CODE</strong></p>
  
  <pre><code>public void onCreate(SQLiteDatabase db) {
  
          // Create user table
          String CREATE_USER_TABLE = "CREATE TABLE " + TABLE_USER + "(" + KEY_ID
                  + " INTEGER PRIMARY KEY AUTOINCREMENT," + KEY_NAME + " TEXT,"
                  + KEY_EMAIL + " TEXT," + KEY_PW + " TEXT," + KEY_SESSION
                  + " INTEGER" + ")";
  
          String CREATE_EXPENSE_TYPE_TABLE = "CREATE TABLE " + TABLE_EXPENSE_TYPE
                  + " (" + KEY_EXPENSE_ID + " INTEGER AUTOINCREMENT" + KEY_EXPENSE_TYPE + " TEXT PRIMARY KEY" + ")";
  
          db.execSQL(CREATE_USER_TABLE);
          db.execSQL(CREATE_EXPENSE_TYPE_TABLE);
      }
  </code></pre>
  
  <p>Method I use to add records</p>
  
  <pre><code>public Long addExpenseType(String expense) {
          SQLiteDatabase db = this.getWritableDatabase();
  
          ContentValues values = new ContentValues();
          values.put(KEY_EXPENSE_TYPE, expense);
  
          Long row = db.insert(TABLE_EXPENSE_TYPE, null, values);
          db.close();
  
          return row;
      }
  </code></pre>
  
  <p>String Values:</p>
  
  <pre><code>    private static final int DATABASE_VERSION = 1;
      private static final String DATABASE_NAME = "expenseManager";
  
      // Database Tables
      private static final String TABLE_USER = "user";
      private static final String TABLE_EXPENSE_TYPE = "expense_type";
  
      // User table columns
      private static final String KEY_ID = "id";
      private static final String KEY_NAME = "full_name";
      private static final String KEY_PW = "password";
      private static final String KEY_EMAIL = "email";
      private static final String KEY_SESSION = "session";
  
      // Expense type table columns
      private static final String KEY_EXPENSE_ID = "id";
      private static final String KEY_EXPENSE_TYPE = "exp_type";
  </code></pre>