title: android SQLite database.. no such table:
body: <p>I have another problem again :(
  The error I encountered with this one is that it does not create a table named contacts but I have the code to create database and yet it does not create it.How to solve this? Thank you again for answering.</p>
  
  <pre><code>package com.mobilebasedsignlanguage;
  
  import java.io.ByteArrayOutputStream;
  import java.util.ArrayList;
  import java.util.List;
  
  import android.app.Activity;
  import android.graphics.Bitmap;
  import android.graphics.BitmapFactory;
  import android.os.Bundle;
  import android.util.Log;
  import android.widget.ListView;
  
  public class alphaconv extends Activity {
  ArrayList&lt;Contact&gt; imageArry = new ArrayList&lt;Contact&gt;();
  ContactImageAdapter adapter;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      // TODO Auto-generated method stub
      super.onCreate(savedInstanceState);
      setContentView(R.layout.alphabetview);
  
      DataBaseHandler db = new DataBaseHandler(this);
      //get image from drawable..
      Bitmap image = BitmapFactory.decodeResource(getResources(), R.drawable.a);
  
      //convert bitmap to byte
      ByteArrayOutputStream stream = new ByteArrayOutputStream();
      image.compress(Bitmap.CompressFormat.JPEG, 100, stream);
      byte imageInByte[] = stream.toByteArray();
      //Inserting Contacts
      Log.d("Insert: ", "Inserting ..");
      db.addContact(new Contact("A", imageInByte));
  
      //Read all contacts from db
      List&lt;Contact&gt; contacts = db.getAllContacts();
      for(Contact cn: contacts) {
          String log = "ID: " + cn.getID() + "Name: " + cn.getName() + ", Image: " + cn.getImage();
  
          Log.d("Result: ", log);
          imageArry.add(cn);
      }
  
      adapter = new ContactImageAdapter(this, R.layout.screen_list, imageArry);
      ListView dataList = (ListView)findViewById(R.id.list);
      dataList.setAdapter(adapter);
  
  }
  
  }
  </code></pre>
  
  <p>here is the other java classes: </p>
  
  <p>Contact.java</p>
  
  <pre><code>package com.mobilebasedsignlanguage;
  
  public class Contact {
  
  int _id;
  String _name;
  byte[] _image;
  
  public Contact() {
  
  }
  
  public Contact(int keyId, String name, byte[] image) {
      this._id = keyId;
      this._name = name;
      this._image = image;
  }
  
  public Contact(String contactID, String name, byte[] image) {
      this._name = name;
      this._image = image;
  }
  
  public Contact(String name, byte[] image) {
      this._name = name;
      this._image = image;
  }
  
  public int getID() {
      return this._id;
  }
  
  public void setID(int keyId ) {
      this._id = keyId;
  }
  
  public String getName() {
      return this._name;
  }
  
  public void setName(String name) {
      this._name = name;
  }
  
  public byte[] getImage() {
      return this._image;
  }
  
  public void setImage(byte[] image) {
      this._image = image;
  }
  
  }
  </code></pre>
  
  <p>ContactImageAdapter.java</p>
  
  <pre><code>package com.mobilebasedsignlanguage;
  
  import java.io.ByteArrayInputStream;
  import java.util.ArrayList;
  
  import android.app.Activity;
  import android.content.Context;
  import android.graphics.Bitmap;
  import android.graphics.BitmapFactory;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.ArrayAdapter;
  import android.widget.ImageView;
  import android.widget.TextView;
  
  public class ContactImageAdapter extends ArrayAdapter&lt;Contact&gt;{
  Context context;
  int layoutResourceId;
  
  ArrayList&lt;Contact&gt; data=new ArrayList&lt;Contact&gt;();
  public ContactImageAdapter(Context context, int layoutResourceId, ArrayList&lt;Contact&gt; data) {
      super(context, layoutResourceId, data);
      this.layoutResourceId = layoutResourceId;
      this.context = context;
      this.data = data;
  }
  
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
      View row = convertView;
      ImageHolder holder = null;
  
      if(row == null)
      {
          LayoutInflater inflater = ((Activity)context).getLayoutInflater();
          row = inflater.inflate(layoutResourceId, parent, false);
  
          holder = new ImageHolder();
          holder.txtTitle = (TextView)row.findViewById(R.id.txtTitle);
          holder.imgIcon = (ImageView)row.findViewById(R.id.imgIcon);
          row.setTag(holder);
      }
      else
      {
          holder = (ImageHolder)row.getTag();
      }
  
      Contact picture = data.get(position);
      holder.txtTitle.setText(picture._name);
  
      byte[] outImage = picture._image;
      ByteArrayInputStream imageStream = new ByteArrayInputStream(outImage);
      Bitmap theImage = BitmapFactory.decodeStream(imageStream);
      holder.imgIcon.setImageBitmap(theImage);
      return row;
  }
  
  static class ImageHolder
  {
      ImageView imgIcon;
      TextView txtTitle;
  }
  
  
  }
  </code></pre>
  
  <p>DbHandler.java</p>
  
  <pre><code>package com.mobilebasedsignlanguage;
  
  import java.util.ArrayList;
  import java.util.List;
  
  import android.content.ContentValues;
  import android.content.Context;
  import android.database.Cursor;
  import android.database.sqlite.SQLiteDatabase;
  import android.database.sqlite.SQLiteOpenHelper;
  
  public class DataBaseHandler extends SQLiteOpenHelper {
  
  private static final int DATABASE_VERSION = 1;
  
  private static final String DATABASE_NAME = "SLdb";
  
  private static final String TABLE_CONTACTS = "contacts";
  
  private static final String KEY_ID = "id";
  private static final String KEY_NAME = "name";
  private static final String KEY_IMAGE = "image";
  
  public DataBaseHandler(Context context) {
      super(context, DATABASE_NAME, null, DATABASE_VERSION);
  }
  
  public void onCreate(SQLiteDatabase db) {
      String CREATE_CONTACTS_TABLE = "CREATE TABLE " + TABLE_CONTACTS + "("
              + KEY_ID + " INTEGER PRIMARY KEY," + KEY_NAME + " TEXT,"
              + KEY_IMAGE + " BLOB" + ")";
      db.execSQL(CREATE_CONTACTS_TABLE);
  }
  
  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
      db.execSQL("DROP TABLE IF EXISTS " + TABLE_CONTACTS);
  
      onCreate(db);
  }
  
  public void addContact(Contact contact) {
      SQLiteDatabase db = this.getWritableDatabase();
  
      ContentValues values = new ContentValues();
      values.put(KEY_NAME, contact._name);
      values.put(KEY_IMAGE, contact._image);
  
      db.insert(TABLE_CONTACTS, null, values);
      db.close();
  }
  
  Contact getContact(int id) {
      SQLiteDatabase db = this.getWritableDatabase();
  
      Cursor cursor = db.query(TABLE_CONTACTS, new String[] { KEY_ID,
              KEY_NAME, KEY_IMAGE }, KEY_ID + "=?",
              new String[] { String.valueOf(id) }, null,null,null,null);
      if(cursor != null)
          cursor.moveToFirst();
  
      Contact contact = new Contact(Integer.parseInt(cursor.getString(0)),
              cursor.getString(1), cursor.getBlob(1));
  
      return contact;
      }
  
  public List&lt;Contact&gt; getAllContacts() {
      List&lt;Contact&gt; contactlist = new ArrayList&lt;Contact&gt;();
      String selectQuery = "SELECT * FROM contacts ORDER BY name";
      SQLiteDatabase db = this.getWritableDatabase();
      Cursor cursor = db.rawQuery(selectQuery, null);
  
      if(cursor.moveToFirst()) {
          do {
              Contact contact = new Contact();
              contact.setID(Integer.parseInt(cursor.getString(0)));
              contact.setName(cursor.getString(1));
              contact.setImage(cursor.getBlob(2));
  
              contactlist.add(contact);
          }while (cursor.moveToNext());
      }
  
      db.close();
  
      return contactlist;
  }
  
  public int updateContact(Contact contact) {
      SQLiteDatabase db = this.getWritableDatabase();
  
      ContentValues values = new ContentValues();
      values.put(KEY_NAME, contact.getName());
      values.put(KEY_IMAGE, contact.getImage());
  
      return db.update(TABLE_CONTACTS, values, KEY_ID + " = ?",
              new String[] { String.valueOf(contact.getID()) });      
  }
  
  public void deleteContact(Contact contact) {
      SQLiteDatabase db = this.getWritableDatabase();
      db.delete(TABLE_CONTACTS, KEY_ID + " = ?",
              new String[] {String.valueOf(contact.getID()) });
      db.close();
  }
  
  public int getContactsCount() {
      String countQuery = "SELECT * FROM " + TABLE_CONTACTS;
      SQLiteDatabase db = this.getReadableDatabase();
      Cursor cursor = db.rawQuery(countQuery, null);
      cursor.close();
  
      return cursor.getCount();
  }
  
  }
  </code></pre>
  
  <p>the error at the log cat is this:</p>
  
  <pre><code>02-18 11:49:25.938: E/SQLiteLog(6044): (1) no such table: contacts
  02-18 11:49:26.078: E/SQLiteDatabase(6044): Error inserting image=[B@40e29b40 name=A
  02-18 11:49:26.078: E/SQLiteDatabase(6044): android.database.sqlite.SQLiteException: no such table: contacts (code 1): , while compiling: INSERT INTO contacts(image,name) VALUES (?,?)
  </code></pre>