0

I have created two tables in SQLite android but whenever I am running this code it says that no tables found with that name, I have tried it on many devices but I am still unable to find errors in the following code.

public void onOpen(SQLiteDatabase db) {
    super.onOpen(db);
}
@Override
public void onCreate(SQLiteDatabase db) {
    db.execSQL("create table peoples" +
            "(personid integer primary key autoincrement," +
            " pname text," +
            " pvehicle text," +
            " ptime text," +
            " pdate text," +
            " startpoint text," +
            " endpoint text)");
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    db.execSQL("DROP TABLE IF EXISTS peoples");
}
public boolean insertPeoples(String pname,String pvehicle, String ptime, String pdate, String start, String end)
{
    try {

        SQLiteDatabase db = this.getWritableDatabase();
        ContentValues values = new ContentValues();
        values.put("pname",pname);
        values.put("pvehicle",pvehicle);
        values.put("ptime",ptime);
        values.put("pdate",pdate);
        values.put("startpoint",start);
        values.put("endpoint",end);
        db.insert("peoples",null,values);

    }
    catch (SQLiteException ex)
    {
        Log.i("MyLog",ex.getMessage());
    }
    return true;
}
public Cursor getAllpeoples()
{
    Cursor res = null;
    try {
        SQLiteDatabase database = this.getReadableDatabase();
        res = database.rawQuery("select * from peoples",null);
    }
    catch (SQLiteException ex)
    {
        Log.e("MyLog",ex.getMessage());
    }
    return res;
}
public void deletePeoples()
{
    SQLiteDatabase db = this.getWritableDatabase();
    db.execSQL("delete from peoples");
}

there is another table that has the similar code and is working fine but this second table is handled by another class and is working fine but this code shows error that no table found with name peoples and so it returns null pointer exception while i try to get records.

Naveed Khan
  • 73
  • 2
  • 15

1 Answers1

-1

I think you are mistake in writing the create table code. Just see this

 public static String createTable="create table details(_id integer Primary key autoincrement,firstname text,lastname text,email text,contactno text)";

public void onCreate(SQLiteDatabase db) 
{
    db.execSQL(createTable);

}

here letter "P" in primary key is capital.

NIKHIL SONI
  • 84
  • 1
  • 1