Exception while adding value to android database(SQLI)
<p>I need a help  with my android simple app. I tried so much to solve it but its useless.
When I am using the <code>additem()</code> method I got an exception:</p>

<p><code>android.database.cursorindexoutofboundsexception index 0 requested with a size of 0</code></p>

<p>the database code</p>

<pre><code>public class DBAdapter extends SQLiteOpenHelper 
{
private static final int DATABASE_VERSION = 1;
private static final String DATABASE_NAME = "Items_Manger";
private static final String Table = "Items";
private static final String creat_Table=
"CREATE TABLE if not exists Items(id  integer primary key autoincrement,name   text,price INTEGER)";
private static final String KEY_ID = "id";
private static final String KEY_NAME = "name";
private static final String KEY_price = "price";

public DBAdapter(Context context) {
    super(context, DATABASE_NAME, null, DATABASE_VERSION);
}


@Override
public void onCreate(SQLiteDatabase db) {
    db.execSQL(creat_Table);
}


@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    db.execSQL("DROP TABLE IF EXISTS " + Table);


    onCreate(db);
}



void additem(Contact contact) {
    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues values = new ContentValues();
    values.put(KEY_ID, contact.get_id());
    values.put(KEY_NAME, contact.get_name()); 
    values.put(KEY_price, contact.get_price());

    db.insert(Table, null, values);      
    db.close(); 
}


 Contact getitem(int id) {
    SQLiteDatabase db = this.getReadableDatabase();
    Cursor cursor = db.query(Table, new String[] { KEY_ID,
            KEY_NAME, KEY_price }, 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),
            Integer.parseInt(cursor.getString(2)));
    // return contact
    return contact;
}


public List&lt;Contact&gt; getallitems() {
    List&lt;Contact&gt; contactList = new ArrayList&lt;Contact&gt;();

    String selectQuery = "SELECT  * FROM " + Table;

    SQLiteDatabase db = this.getWritableDatabase();
    Cursor cursor = db.rawQuery(selectQuery, null);


    if (cursor.moveToFirst()) {
        do {
            Contact contact = new Contact();
            contact.set_id(Integer.parseInt(cursor.getString(0)));
            contact.set_name(cursor.getString(1));
            contact.set_price(Integer.parseInt(cursor.getString(2)));
            // Adding contact to list
            contactList.add(contact);
        } while (cursor.moveToNext());
    }


    return contactList;
}

//**************************************************************
public int updateitem(Contact contact) {
    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues values = new ContentValues();
    values.put(KEY_NAME, contact.get_name());
    values.put(KEY_price, contact.get_price());


    return db.update(Table, values, KEY_ID + " = ?",
            new String[] { String.valueOf(contact.get_id()) });
}

//**************************************************************
public void deleteitem(Contact contact) {
    SQLiteDatabase db = this.getWritableDatabase();
    db.delete(Table, KEY_ID + " = ",new String[] { String.valueOf(contact.get_id()) });           
    db.close();
}
</code></pre>

<p>the button :</p>

<pre><code>    insert.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            int idd= Integer.parseInt(eid.getText().toString());
            String namee= ename.getText().toString();
            int pricee = Integer.parseInt(eprice.getText().toString());
            Contact c = new Contact();
            c=db.getitem(idd);
            db.additem(new Contact(idd,namee,pricee));  


        }
    });
</code></pre>

<p>the Contact class</p>

<pre><code>public class Contact {
int id;
int price;
String name;

public Contact(){}

public Contact(int _id, String _name, int _price){
this.id = _id;
this.name = _name;
this.price=_price;
}
public Contact(String _name, int _price){
this.name = _name;
this.price=_price;
}
public Contact(int _id){
this.id=_id;
}

public int get_id(){return this.id;}
public int get_price(){return this.price;}
public String get_name(){return this.name;}

public void set_id(int _id){this.id=_id;}
public void set_price(int _price){this.price=_price;}
public void set_name(String _name){this.name=_name;}

}
</code></pre>
