title: Sqlite android: table not found
body: <p>I keep on getting this error saying that the table in my database doesn't exist but the table was declared.</p>
  
  <p>So, I have this class to create appointments into a database, which is:</p>
  
  <pre><code>package com.example.calendar;
  
  import android.os.Bundle;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.widget.Button;
  import android.widget.CalendarView;
  import android.widget.EditText;
  import android.app.Activity;
  import android.content.ContentValues;
  import android.content.Intent;
  import android.database.Cursor;
  import android.database.sqlite.SQLiteDatabase;
  import com.example.calendar.Appointment;
  import static com.example.calendar.Constants.KEY_DATE;
  import static com.example.calendar.Constants.KEY_DETAILS;
  import static com.example.calendar.Constants.KEY_ID;
  import static com.example.calendar.Constants.KEY_TIME;
  import static com.example.calendar.Constants.KEY_TITLE;
  import static com.example.calendar.Constants.TABLE_APP;
  
  
  public class CreateAppointment extends Activity implements OnClickListener{
  
      EditText titleTextBox, timeTextBox, detailsTextBox;
      int[] dateSelected = new int[3];
  
      protected void onCreate(Bundle savedInstanceState) {
  
          super.onCreate(savedInstanceState);
          setContentView(R.layout.create);
  
          titleTextBox = (EditText) findViewById(R.id.apptTitle);
          timeTextBox = (EditText) findViewById(R.id.apptTime);
          detailsTextBox = (EditText) findViewById(R.id.apptDetails);
  
          View createButton = (Button) findViewById(R.id.apptSave);
          String dateToPass = null;
          Bundle getExtraFromMain = getIntent().getExtras();
          if(getExtraFromMain != null){
              dateSelected = getExtraFromMain.getIntArray(dateToPass);
          }
  
          createButton.setOnClickListener(this);
  
      }
  
  
  
      private Cursor cursor(){
          DBHandler appointment = new DBHandler(this);
          SQLiteDatabase db = appointment.getReadableDatabase();
          String[] getValueFrom = {KEY_DATE, KEY_TITLE, KEY_TIME, KEY_DETAILS};
          Cursor cursor = db.query(TABLE_APP, getValueFrom, null, null, null, null, KEY_DATE + " ASC");
          return cursor;
      }
  
      private void save(){
          String getTime = timeTextBox.getText().toString();
          String getTitle = titleTextBox.getText().toString();
          String getDetails = detailsTextBox.getText().toString();
          DBHandler appointment = new DBHandler(this);
          SQLiteDatabase db = appointment.getWritableDatabase();
          ContentValues values = new ContentValues();
          values.put(KEY_TITLE, getTitle);
          values.put(KEY_TIME, getTime);
          values.put(KEY_DETAILS, getDetails);
          values.put(KEY_DATE, dateSelected[0] + "/" + dateSelected[1] + "/" + dateSelected[2]);
          db.insertOrThrow(TABLE_APP, null, values);
          appointment.close();
      }
  
      @Override
      public void onClick(View v) {
          // TODO Auto-generated method stub
  
          switch(v.getId()){
  
          case R.id.apptSave:
              save();
              finish();
              break;
  
          }
  
      }
  
  }
  </code></pre>
  
  <p>And, of course, my handler:</p>
  
  <pre><code>package com.example.calendar;
  
  import android.content.Context;
  import android.database.sqlite.SQLiteDatabase;
  import android.database.sqlite.SQLiteOpenHelper;
  import static com.example.calendar.Constants.KEY_DATE;
  import static com.example.calendar.Constants.KEY_DETAILS;
  import static com.example.calendar.Constants.KEY_ID;
  import static com.example.calendar.Constants.KEY_TIME;
  import static com.example.calendar.Constants.KEY_TITLE;
  import static com.example.calendar.Constants.TABLE_APP;
  
  public class DBHandler extends SQLiteOpenHelper {
  
      //Variables needed
      private static final int DATABASE_VERSION = 1;
      private static final String DATABASE_NAME = "appts.db";// database name
  
      public DBHandler(Context context){
          super(context, DATABASE_NAME, null, DATABASE_VERSION);
      }
  
      @Override//create table
      public void onCreate(SQLiteDatabase db){
          String CREATE_APPOINTMENTS_TABLE = "CREATE TABLE " + TABLE_APP + " ("
                  + KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_DATE + " TEXT NOT NULL,"
                  + KEY_TITLE + " TEXT NOT NULL, " + KEY_TIME + " TEXT NOT NULL, " + KEY_DETAILS + " TEXT NOT NULL" + ");";
          db.execSQL(CREATE_APPOINTMENTS_TABLE);
      }
  
      @Override//when upgraded, trigger
      public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion){
          db.execSQL("DROP TABLE IF EXISTS " + TABLE_APP);//delete table from older version
          onCreate(db);//create new table
      }
  
  
  }
  </code></pre>
  
  <p>And additionally, the interface where the table name was declared:</p>
  
  <pre><code>package com.example.calendar;
  
  import android.provider.BaseColumns;
  
  public interface Constants extends BaseColumns{
  
      public static final String TABLE_APP = "appointments";// table name
      public static final String KEY_ID = "id";
      public static final String KEY_DATE = "date";
      public static final String KEY_TITLE = "title";
      public static final String KEY_TIME = "time";
      public static final String KEY_DETAILS = "details";
  
  }
  </code></pre>
  
  <p>When I hit the button on the <code>Activity</code>, Logcat gives me this:</p>
  
  <pre><code>03-24 02:18:28.134: E/AndroidRuntime(800): android.database.sqlite.SQLiteException: no such table: appointments: , while compiling: INSERT INTO appointments(time,title,date,details) VALUES (?,?,?,?)
  03-24 02:18:28.134: E/AndroidRuntime(800):  at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
  03-24 02:18:28.134: E/AndroidRuntime(800):  at android.database.sqlite.SQLiteCompiledSql.&lt;init&gt;(SQLiteCompiledSql.java:64)
  03-24 02:18:28.134: E/AndroidRuntime(800):  at android.database.sqlite.SQLiteStatement.executeInsert(SQLiteStatement.java:112)
  03-24 02:18:28.134: E/AndroidRuntime(800):  at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1718)
  03-24 02:18:28.134: E/AndroidRuntime(800):  at android.database.sqlite.SQLiteDatabase.insertOrThrow(SQLiteDatabase.java:1617)
  03-24 02:18:28.134: E/AndroidRuntime(800):  at com.example.calendar.CreateAppointment.save(CreateAppointment.java:69)
  03-24 02:18:28.134: E/AndroidRuntime(800):  at com.example.calendar.CreateAppointment.onClick(CreateAppointment.java:80)
  </code></pre>
  
  <p><strong>Note:</strong> lines 69 and 80 are:</p>
  
  <p>69:</p>
  
  <pre><code>db.insertOrThrow(TABLE_APP, null, values);
  </code></pre>
  
  <p>80:</p>
  
  <pre><code>save();//from switch statement
  </code></pre>
  
  <p>Can someone please help me??</p>