2016-07-21 47 views
0

我已經在SQLite的android中創建了兩個表,但是每當我運行這段代碼時它說沒有找到那個名字的表,我已經在很多設備上嘗試了它,但我仍然無法找到錯誤下面的代碼。SQLite Android - 表未找到

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"); 
} 

存在具有類似的代碼另一個表,並工作正常,但第二個表由另一個類處理,並工作正常,但此代碼顯示錯誤,沒有與名人們發現並表,所以它返回null指針異常,而我試圖獲取記錄。

回答

-1

我認爲你寫錯了創建表代碼。看到這個

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); 

} 

這裏的主要關鍵字中的字母「P」是大寫。

+0

不,這不是問題 –