title: Android SQLite issue - table __ has no column named ___
body: <p>I am a new developer and I am having an SQLite issue.  Some reason I am not able to add two columns (table_row_three, and table_row_four) to my SQLite data table.  When I read the database file currently, it has a table with "id", "table_row_one", and "table_row_two", but is missing "table_row_three" and "table_row_four".</p>
  
  <p>The error message in my logcat reads: "(1) table database_table has no column named table_row_three".</p>
  
  <p>I am really confused to why the columns "table_row_three" and "table_row_four" are not showing up on my table, and why only "id", "table_row_one", and "table_row_two" appear in my data table.</p>
  
  <p>Here is my Database class:</p>
  
  <pre><code>DatabaseHandler.java
  
  
  import java.util.ArrayList;
  
  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;
  import android.util.Log;
  
  
  
  public class DatabaseHandler
  {
  
  Context context;
  
  
  private SQLiteDatabase db;
  
  
  private final String DB_NAME = "database_name";
  private final int DB_VERSION = 2;
  
  
  private final String TABLE_NAME = "database_table";
  private final String TABLE_ROW_ID = "id";
  
  private final String TABLE_ROW_ONE = "table_row_one";
  private final String TABLE_ROW_TWO = "table_row_two";
  private final String TABLE_ROW_THREE = "table_row_three";
  private final String TABLE_ROW_FOUR = "table_row_four";
  
  public DatabaseHandler(Context context)
  {
      this.context = context;
  
      // create or open the database
      CustomSQLiteOpenHelper helper = new CustomSQLiteOpenHelper(context);
      this.db = helper.getWritableDatabase();
  }
  
  
  public void addRow(String rowStringOne, String rowStringTwo, String rowStringThree, String rowStringFour)
  {
      // this is a key value pair holder used by android's SQLite functions
      ContentValues values = new ContentValues();
      //TABLE_ROW_ONE = Title
      //TABLE_ROW_TWO = Location
      //TABLE_ROW_THREE = Notes
      //TABLE_ROW_FOUR = Picture
      values.put(TABLE_ROW_ONE, rowStringOne);
      values.put(TABLE_ROW_TWO, rowStringTwo);
      values.put(TABLE_ROW_THREE, rowStringThree);
      values.put(TABLE_ROW_FOUR, rowStringFour);
  
      // ask the database object to insert the new data
      try{db.insert(TABLE_NAME, null, values);}
      catch(Exception e)
      {
          Log.e("DB ERROR", e.toString());
          e.printStackTrace();
      }
  }
  
  
  
  
  public void deleteRow(long rowID)
  {
      // ask the database manager to delete the row of given id
      try {db.delete(TABLE_NAME, TABLE_ROW_ID + "=" + rowID, null);}
      catch (Exception e)
      {
          Log.e("DB ERROR", e.toString());
          e.printStackTrace();
      }
  }
  
  public void updateRow(long rowID, String rowStringOne, String rowStringTwo, String rowStringThree, String rowStringFour)
  {
      ContentValues values = new ContentValues();
      values.put(TABLE_ROW_ONE, rowStringOne);
      values.put(TABLE_ROW_TWO, rowStringTwo);
      values.put(TABLE_ROW_THREE, rowStringThree);
      values.put(TABLE_ROW_FOUR, rowStringFour);
  
      try {db.update(TABLE_NAME, values, TABLE_ROW_ID + "=" + rowID, null);}
      catch (Exception e)
      {
          Log.e("DB Error", e.toString());
          e.printStackTrace();
      }
  }
  
  
  public ArrayList&lt;Object&gt; getRowAsArray(long rowID)
  {
  
      ArrayList&lt;Object&gt; rowArray = new ArrayList&lt;Object&gt;();
      Cursor cursor;
  
      try
      {
  
          cursor = db.query
                  (
                          TABLE_NAME,
                          new String[] { TABLE_ROW_ID, TABLE_ROW_ONE, TABLE_ROW_TWO, TABLE_ROW_THREE, TABLE_ROW_FOUR },
                          TABLE_ROW_ID + "=" + rowID,
                          null, null, null, null, null
                  );
  
  
          cursor.moveToFirst();
  
  
          if (!cursor.isAfterLast())
          {
              do
              {
                  rowArray.add(cursor.getLong(0));
                  rowArray.add(cursor.getString(1));
                  rowArray.add(cursor.getString(2));
                  rowArray.add(cursor.getString(3));
                  rowArray.add(cursor.getString(4));
              }
              while (cursor.moveToNext());
          }
  
  
          cursor.close();
      }
      catch (SQLException e)
      {
          Log.e("DB ERROR", e.toString());
          e.printStackTrace();
      }
  
      // return the ArrayList containing the given row from the database.
      return rowArray;
  }
  
  
  
  
  
  
  public ArrayList&lt;ArrayList&lt;Object&gt;&gt; getAllRowsAsArrays()
  {
  
      ArrayList&lt;ArrayList&lt;Object&gt;&gt; dataArrays = new ArrayList&lt;ArrayList&lt;Object&gt;&gt;();
  
  
      Cursor cursor;
  
      try
      {
          cursor = db.query(
                  TABLE_NAME,
                  new String[]{TABLE_ROW_ID, TABLE_ROW_ONE, TABLE_ROW_TWO, TABLE_ROW_THREE, TABLE_ROW_FOUR},
                  null, null, null, null, null
          );
  
          cursor.moveToFirst();
  
          if (!cursor.isAfterLast())
          {
              do
              {
                  ArrayList&lt;Object&gt; dataList = new ArrayList&lt;Object&gt;();
  
                  dataList.add(cursor.getLong(0));
                  dataList.add(cursor.getString(1));
                  dataList.add(cursor.getString(2));
                  dataList.add(cursor.getString(3));
                  dataList.add(cursor.getString(4));
                  dataArrays.add(dataList);
              }
              while (cursor.moveToNext());
          }
      }
      catch (SQLException e)
      {
          Log.e("DB Error", e.toString());
          e.printStackTrace();
      }
  
      return dataArrays;
  }
  
  
  
  
  
  
  
  
  private class CustomSQLiteOpenHelper extends SQLiteOpenHelper
  {
      public CustomSQLiteOpenHelper(Context context)
      {
          super(context, DB_NAME, null, DB_VERSION);
      }
  
      @Override
      public void onCreate(SQLiteDatabase db)
      {
  
          String newTableQueryString = "create table " +
                  TABLE_NAME +
                  " (" +
                  TABLE_ROW_ID + " integer primary key autoincrement not null," +
                  TABLE_ROW_ONE + " text," +
                  TABLE_ROW_TWO + " text" +
                  TABLE_ROW_THREE + " text" +
                  TABLE_ROW_FOUR + " text" +
                  ");";
          db.execSQL(newTableQueryString);
      }
  
  
      @Override
      public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
      {
  
      }
  }
  </code></pre>
  
  <p>Here is my Test class:</p>
  
  <pre><code>public class DatabaseExampleActivity extends Activity {
  EditText textFieldOne, textFieldTwo, textFieldThree, textFieldFour,
          idField,
          updateIDField, updateTextFieldOne, updateTextFieldTwo,updateTextFieldThree, updateTextFieldFour;
  
  Button addButton, deleteButton, retrieveButton, updateButton;
  
  TableLayout dataTable;
  
  DatabaseHandler db;
  
  
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      // this try catch block returns better error reporting to the log
      try {
          // Android specific calls
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_databaseexample);
  
          // create the database manager object
          db = new DatabaseHandler(this);
  
          // create references and listeners for the GUI interface
          setupViews();
  
          // make the buttons clicks perform actions
          addButtonListeners();
  
          // load the data table
          updateTable();
      } catch (Exception e) {
          Log.e("ERROR", e.toString());
          e.printStackTrace();
      }
  }
  
  
  private void setupViews() {
      // THE DATA TABLE
      dataTable = (TableLayout) findViewById(R.id.data_table);
  
      // THE DATA FORM FIELDS
      textFieldOne = (EditText) findViewById(R.id.text_field_one);
      textFieldTwo = (EditText) findViewById(R.id.text_field_two);
      textFieldThree = (EditText) findViewById(R.id.text_field_three);
      textFieldFour = (EditText) findViewById(R.id.text_field_four);
      idField = (EditText) findViewById(R.id.id_field);
      updateIDField = (EditText) findViewById(R.id.update_id_field);
      updateTextFieldOne = (EditText) findViewById(R.id.update_text_field_one);
      updateTextFieldTwo = (EditText) findViewById(R.id.update_text_field_two);
      updateTextFieldThree = (EditText) findViewById(R.id.update_text_field_three);
      updateTextFieldFour = (EditText) findViewById(R.id.update_text_field_four);
  
      addButton = (Button) findViewById(R.id.add_button);
      deleteButton = (Button) findViewById(R.id.delete_button);
      retrieveButton = (Button) findViewById(R.id.retrieve_button);
      updateButton = (Button) findViewById(R.id.update_button);
  }
  
  
  
  private void addButtonListeners() {
      addButton.setOnClickListener
              (
                      new View.OnClickListener() {
                          @Override
                          public void onClick(View v) {
                              addRow();
                          }
                      }
              );
  
      deleteButton.setOnClickListener
              (
                      new View.OnClickListener() {
                          @Override
                          public void onClick(View v) {
                              deleteRow();
                          }
                      }
              );
  
      updateButton.setOnClickListener
              (
                      new View.OnClickListener() {
                          @Override
                          public void onClick(View v) {
                              updateRow();
                          }
                      }
              );
  
      retrieveButton.setOnClickListener
              (
                      new View.OnClickListener() {
                          @Override
                          public void onClick(View v) {
                              retrieveRow();
                          }
                      }
              );
  
  }
  
  
  private void addRow() {
      try {
          // ask the database manager to add a row given the two strings
          db.addRow
                  (
                          textFieldOne.getText().toString(),
                          textFieldTwo.getText().toString(),
                          textFieldThree.getText().toString(),
                          textFieldFour.getText().toString()
  
                  );
  
          // request the table be updated
          updateTable();
  
          // remove all user input from the Activity
          emptyFormFields();
      } catch (Exception e) {
          Log.e("Add Error", e.toString());
          e.printStackTrace();
      }
  }
  
  
  private void deleteRow() {
      try {
          // ask the database manager to delete the row with the give rowID.
          db.deleteRow(Long.parseLong(idField.getText().toString()));
  
          // request the table be updated
          updateTable();
  
          // remove all user input from the Activity
          emptyFormFields();
      } catch (Exception e) {
          Log.e("Delete Error", e.toString());
          e.printStackTrace();
      }
  }
  
  
  private void retrieveRow() {
      try {
          // The ArrayList that holds the row data
          ArrayList&lt;Object&gt; row;
          // ask the database manager to retrieve the row with the given rowID
          row = db.getRowAsArray(Long.parseLong(updateIDField.getText().toString()));
  
          // update the form fields to hold the retrieved data
          updateTextFieldOne.setText((String) row.get(1));
          updateTextFieldTwo.setText((String) row.get(2));
          updateTextFieldThree.setText((String) row.get(3));
          updateTextFieldFour.setText((String) row.get(4));
  
      } catch (Exception e) {
          Log.e("Retrieve Error", e.toString());
          e.printStackTrace();
      }
  }
  
  private void updateRow() {
      try {
          // ask the database manager to update the row based on the information
          // found in the corresponding user entry fields
          db.updateRow
                  (
                          Long.parseLong(updateIDField.getText().toString()),
                          updateTextFieldOne.getText().toString(),
                          updateTextFieldTwo.getText().toString(),
                          updateTextFieldThree.getText().toString(),
                          updateTextFieldFour.getText().toString()
                  );
  
          updateTable();
  
          emptyFormFields();
      } catch (Exception e) {
          Log.e("Update Error", e.toString());
          e.printStackTrace();
      }
  }
  
  
  private void emptyFormFields() {
      textFieldOne.setText("");
      textFieldTwo.setText("");
      textFieldThree.setText("");
      textFieldFour.setText("");
      idField.setText("");
      updateIDField.setText("");
      updateTextFieldOne.setText("");
      updateTextFieldTwo.setText("");
      updateTextFieldThree.setText("");
      updateTextFieldFour.setText("");
  }
  
  
  private void updateTable() {
      // delete all but the first row.  remember that the count
      // starts at one and the index starts at zero
      while (dataTable.getChildCount() &gt; 1) {
          // while there are at least two rows in the table widget, delete
          // the second row.
          dataTable.removeViewAt(1);
      }
  
      // collect the current row information from the database and
      // store it in a two dimensional ArrayList
      ArrayList&lt;ArrayList&lt;Object&gt;&gt; data = db.getAllRowsAsArrays();
  
      // iterate the ArrayList, create new rows each time and add them
      // to the table widget.
      for (int position = 0; position &lt; data.size(); position++) {
          TableRow tableRow = new TableRow(this);
  
          ArrayList&lt;Object&gt; row = data.get(position);
  
          TextView idText = new TextView(this);
          idText.setText(row.get(0).toString());
          tableRow.addView(idText);
  
          TextView textOne = new TextView(this);
          textOne.setText(row.get(1).toString());
          tableRow.addView(textOne);
  
          TextView textTwo = new TextView(this);
          textTwo.setText(row.get(2).toString());
          tableRow.addView(textTwo);
  
  
          TextView textThree = new TextView(this);
          textThree.setText(row.get(3).toString());
          tableRow.addView(textThree);
  
  
          TextView textFour = new TextView(this);
          textFour.setText(row.get(4).toString());
          tableRow.addView(textFour);
  
  
          dataTable.addView(tableRow);
      }
  }
  </code></pre>