title: SQLite problems on android - onCreate or insert
body: <p>This chunk of my app is causing me some grief... either my table isn't getting created properly or the insert statements are out of line. I followed this tutorial which seemed to be well explained <a href="http://www.giantflyingsaucer.com/blog/?p=1342" rel="nofollow">http://www.giantflyingsaucer.com/blog/?p=1342</a> but I can't seem to find the differences between my code and theirs. Any advice would be greatly appreciated!</p>
  
  <p>Here is my MainActivity code:</p>
  
  <p>private SQLiteIngAssistant sqlliteIngAssistant;</p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      sqlliteIngAssistant = new SQLiteIngAssistant(MainActivity.this);
      sqlliteIngAssistant.openDB();
  
      sqlliteIngAssistant.insertIng("Foo");
      String[] autofillIngs = sqlliteIngAssistant.getAllIngNames();
  </code></pre>
  
  <p>}</p>
  
  <p>Here is my SQL assistant:</p>
  
  <pre><code>public class SQLiteIngAssistant extends SQLiteOpenHelper {
      private static final String DB_NAME = "usingsqlite.db";
      private static final int DB_VERSION_NUMBER = 1;
      private static final String DB_TABLE_NAME = "ings";
      private static final String DB_COLUMN_1_NAME = "ing_name";
      private static final String DB_COLUMN_2_NAME = "cons";
  
      private static final String DB_CREATE_SCRIPT = "create table " + DB_TABLE_NAME +
              " (_id string primary key " + DB_COLUMN_1_NAME + ", " + DB_COLUMN_2_NAME + " text not null);)";
  
      private SQLiteDatabase sqliteDBInstance = null;
  
      public SQLiteIngAssistant(Context context){
          super(context, DB_NAME, null, DB_VERSION_NUMBER);
      }
  
      @Override
      public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion){
          // TODO: Implement onUpgrade
      }
  
      @Override
      public void onCreate(SQLiteDatabase sqliteDBInstance){
          Log.i("onCreate", "Creating the database...");
          sqliteDBInstance.execSQL(DB_CREATE_SCRIPT);
      }
  
      public void openDB() throws SQLException{
          Log.i("openDB", "Checking sqliteDBInstance...");
          if(this.sqliteDBInstance == null){
              Log.i("openDB", "Creating sqliteDBInstance...");
              this.sqliteDBInstance = this.getWritableDatabase();
          }
      }
  
      public long insertIng(String Name){
          ContentValues contentValues = new ContentValues();
          contentValues.put(DB_COLUMN_1_NAME, Name);
          return this.sqliteDBInstance.insert(DB_TABLE_NAME, null, contentValues);
      }
  
  
      public String[] getAllIngNames(){
          Cursor cursor = this.sqliteDBInstance.query(DB_TABLE_NAME, new String[] {DB_COLUMN_1_NAME}, null, null, null, null, null);
  
          if(cursor.getCount() &gt;0){
              String[] str = new String[cursor.getCount()];
              int i = 0;
  
              while (cursor.moveToNext()){
                  str[i] = cursor.getString(cursor.getColumnIndex(DB_COLUMN_1_NAME));
                  i++;
              }
              return str;
          } else {
              return new String[] {};
          }
      }
  }
  </code></pre>
  
  <p>Here is the stack trace:</p>
  
  <pre><code>01-11 19:23:04.382  14630-14630/com.example.ciltkick.nom E/SQLiteDatabase﹕ Error inserting ing_name=Foo
      android.database.sqlite.SQLiteException: table ings has no column named ing_name (code 1): , while compiling: INSERT INTO ings(ing_name) VALUES (?)
              at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
              at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:893)
              at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:504)
              at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
              at android.database.sqlite.SQLiteProgram.&lt;init&gt;(SQLiteProgram.java:58)
              at android.database.sqlite.SQLiteStatement.&lt;init&gt;(SQLiteStatement.java:31)
              at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1475)
              at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1347)
              at com.example.ciltkick.nom.SQLiteIngAssistant.insertIng(SQLiteIngAssistant.java:61)
              at com.example.ciltkick.nom.MainActivity.onCreate(MainActivity.java:65)
              at android.app.Activity.performCreate(Activity.java:5008)
              at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2035)
              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2096)
              at android.app.ActivityThread.access$600(ActivityThread.java:138)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1207)
              at android.os.Handler.dispatchMessage(Handler.java:99)
              at android.os.Looper.loop(Looper.java:213)
              at android.app.ActivityThread.main(ActivityThread.java:4787)
              at java.lang.reflect.Method.invokeNative(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:511)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
              at dalvik.system.NativeStart.main(Native Method)
  01-11 19:23:04.422  14630-14630/com.example.ciltkick.nom E/AndroidRuntime﹕ FATAL EXCEPTION: main
      java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.ciltkick.nom/com.example.ciltkick.nom.MainActivity}: android.database.sqlite.SQLiteException: no such column: ing_name (code 1): , while compiling: SELECT ing_name FROM ings
              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2071)
              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2096)
              at android.app.ActivityThread.access$600(ActivityThread.java:138)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1207)
              at android.os.Handler.dispatchMessage(Handler.java:99)
              at android.os.Looper.loop(Looper.java:213)
              at android.app.ActivityThread.main(ActivityThread.java:4787)
              at java.lang.reflect.Method.invokeNative(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:511)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
              at dalvik.system.NativeStart.main(Native Method)
       Caused by: android.database.sqlite.SQLiteException: no such column: ing_name (code 1): , while compiling: SELECT ing_name FROM ings
              at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
              at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:893)
              at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:504)
              at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
              at android.database.sqlite.SQLiteProgram.&lt;init&gt;(SQLiteProgram.java:58)
              at android.database.sqlite.SQLiteQuery.&lt;init&gt;(SQLiteQuery.java:37)
              at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
              at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1322)
              at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1169)
              at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1040)
              at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1208)
              at com.example.ciltkick.nom.SQLiteIngAssistant.getAllIngNames(SQLiteIngAssistant.java:89)
              at com.example.ciltkick.nom.MainActivity.onCreate(MainActivity.java:77)
              at android.app.Activity.performCreate(Activity.java:5008)
              at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2035)
              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2096)
              at android.app.ActivityThread.access$600(ActivityThread.java:138)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1207)
              at android.os.Handler.dispatchMessage(Handler.java:99)
              at android.os.Looper.loop(Looper.java:213)
              at android.app.ActivityThread.main(ActivityThread.java:4787)
              at java.lang.reflect.Method.invokeNative(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:511)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
              at dalvik.system.NativeStart.main(Native Method)
  </code></pre>