Click here to Skip to main content
15,895,709 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Good morning every body;

I'm trying to make a database class in android, and it is done, I've created a table successfully too. The problem comes when I want to insert rows to the table using ContentValues, it tries to insert the row in different order from the table fields which cuases an error in the logcat saying : no such table as follows:

These are my variables:

Java
private static final String row_ID="RID";
   private static final String row_NAME="NAME";
   private static final String row_EMAIL="EMAIL";
   private static final String row_WEBSITE="WEBSITE";
   private static final String row_TELEPHONE1="PHONE_NUMBER1";
   private static final String row_TELEPHONE2="PHONE_NUMBER2";
   private static final String row_TELEPHONE3="PHONE_NUMBER3";
   private static final String row_TELEPHONE4="PHONE_NUMBER4";
   private static final String row_TELEPHONE5="PHONE_NUMBER5";
   private static final String db_NAME="ContactsDb";
   private static final String tab_NAME="ContactsTab";
   private static final int db_VERSION=2;
   private dbHelper ourHelper;
   private final Context ourContext;
   private SQLiteDatabase ourDatabase;


My table :

Java
String CREATE_TABLE="CREATE TABLE " + db_NAME + " ("
                        + row_ID + " INT PRIMARY KEY AUTOINCREMENT,"
                        + row_NAME + " TEXT, "
                        + row_EMAIL + " TEXT, "
                        + row_WEBSITE + " TEXT, "
                        + row_TELEPHONE1 + " TEXT, "
                        + row_TELEPHONE2 + " TEXT, "
                        + row_TELEPHONE3 + " TEXT, "
                        + row_TELEPHONE4 + " TEXT, "
                        + row_TELEPHONE5 + " TEXT);";
    db_name.execSQL(CREATE_TABLE);



Inserting rows using ContentValues :

Java
    public long createEntry(String name, String email, String website, String telephone1, String telephone2, String telephone3, String telephone4, String telephone5)
{
    ContentValues cv = new ContentValues ();

    Log.v("STATUS", "getting input data..");

    cv.put(row_NAME, name);
    cv.put(row_EMAIL, email);
    cv.put(row_WEBSITE, website);       
    cv.put(row_TELEPHONE1, telephone1);
    cv.put(row_TELEPHONE2, telephone2);
    cv.put(row_TELEPHONE3, telephone3);
    cv.put(row_TELEPHONE4, telephone4);
    cv.put(row_TELEPHONE5, telephone5);
    Log.v("STATUS", "got input data, inserting data....");

    return ourDatabase.insert(tab_NAME, null, cv);
}



So, when I run this application it succeeds doing all these until it arrives to ourDatabase.insert(tab_NAME, null, cv); it shows the error:

Java
SQLiteLog            (1) no such table: ContactsTab
SQLiteDatabase       Error inserting Name=Ahlam M. Hussain   PHONE_NUMBER5=
                     PHONE_NUMBER4=   PHONE_NUMBER3=    PHONE_NUMBER2=059999999
                     PHONE_NUMBER1= 09299999    EMAIL=ahlam@ahlam.com  WEBSITE=
SQLiteDatabase       android.database.sqlite.SQLiteException: no such table:
                     ContactsTab (code 1): ,while compiling: INSERT INTO
                     ContactsTab(NAME, PHONE_NUMBER5 PHONE_NUMBER4 PHONE_NUMBER3
                     PHONE_NUMBER2 PHONE_NUMBER1, EMAIL, WEBSITE) VALUES
                     (?,?,?,?,?,?,?,?)


You can notice that it is trying to insert row in different fields orderm so it is not recognizing the table..

So what to do ??? I really got suck of that..
Posted
Updated 21-Dec-12 5:08am
v4

What do you sent to the DB?

The value there says "EWebsite" ???
 
Share this answer
 
Comments
Ahlam Hussain 21-Dec-12 7:08am    
It seems a writing mistake while copying the error log..
it is Website not EWebsite..
I had been writing the Database name
Java
db_NAME
instead of the table name
Java
tab_NAME
in the create table statement :)

Thanks for every one gave help..
 
Share this answer
 
Comments
TorstenH. 21-Dec-12 11:14am    
....ok.....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900