我正在研究改進我之前爲我的應用程序編寫的數據庫。以前的數據庫工作正常,但只是混亂,我做了愚蠢的事情,嘗試和清理它。這造成了一個不可思議的錯誤,我無法開始解釋。經過多次追溯,最後回來,讓數據庫看起來,據我所知,與我以前的數據庫相同,我仍然得到詛咒的錯誤。有誰知道什麼是無效的表格異常?
錯誤:
03-02 10:38:30.205: ERROR/AndroidRuntime(505): FATAL EXCEPTION: JobLister: RunThread jobs
03-02 10:38:30.205: ERROR/AndroidRuntime(505): java.lang.IllegalStateException: Invalid tables
03-02 10:38:30.205: ERROR/AndroidRuntime(505): at android.database.sqlite.SQLiteDatabase.findEditTable(SQLiteDatabase.java:1313)
03-02 10:38:30.205: ERROR/AndroidRuntime(505): at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1414)
03-02 10:38:30.205: ERROR/AndroidRuntime(505): at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1370)
03-02 10:38:30.205: ERROR/AndroidRuntime(505): at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1450)
03-02 10:38:30.205: ERROR/AndroidRuntime(505): at com.android.appion.arm.database.Database.getRecord(Database.java:120)
03-02 10:38:30.205: ERROR/AndroidRuntime(505): at com.android.appion.arm.database.Database.getRecord(Database.java:107)
03-02 10:38:30.205: ERROR/AndroidRuntime(505): at com.android.appion.arm.database.Database.getRecord(Database.java:97)
03-02 10:38:30.205: ERROR/AndroidRuntime(505): at com.android.appion.arm.activities.JobLister.getJobs(JobLister.java:69)
03-02 10:38:30.205: ERROR/AndroidRuntime(505): at com.android.appion.arm.activities.JobLister.access$3(JobLister.java:66)
03-02 10:38:30.205: ERROR/AndroidRuntime(505): at com.android.appion.arm.activities.JobLister$2.run(JobLister.java:52)
03-02 10:38:30.205: ERROR/AndroidRuntime(505): at java.lang.Thread.run(Thread.java:1020)
所以很自然我也跟着鋸痕跡,看到它源於一個電話讓我在我的活動之一,我已經保存在我的服務(自然)數據庫。
從活動的數據庫調用:
Cursor c = mService.getDatabase().getRecord(new Table.Jobs());
這一切都似乎是正確的。使用服務我得到數據庫,並與數據庫獲取表作業的所有記錄。
的getRecord方法步進和職位表定義:
public Cursor getRecord(DataTable table) {
return getRecord(table, null);
}
public Cursor getRecord(DataTable table, String[] columns) {
return getRecord(table, columns, null);
}
/**
* Return a Cursor with every item in which data is only coming from columns,
* and the records satisfies all selection requirements.
* @param table The table to query.
* @param columns The columns to retieve data.
* @param selection The requirements to base the data collection on. (WHERE statement
* without WHERE).
* @return The Cursor full of queried items.
*/
public Cursor getRecord(DataTable table, String[] columns, String selection) {
return mDB.query(table.TITLE, (columns == null) ? new String[] {"*"} : columns,
selection, null, null, null, null);
}
而且表:
public static class Jobs extends DataTable {
public static final String TITLE = "jobs";
public static final String[] FIELD = {"job_id",
"job_name", // User given name
"job_contact", // client
"job_location", // The location of the job
"job_notes",
"job_summary", // The byte object of a JobSummary
"wkb_name", // the workbench that is being used for the job
"job_startdate",
"job_enddate"};
public Jobs() { super(); }
public String getTable() {
return "create table " + TITLE +
"(" + FIELD[0] + " integer primary key autoincrement, " +
FIELD[1] + " text, " +
FIELD[2] + " blob, " +
FIELD[3] + " blob, " +
FIELD[4] + " text, " +
FIELD[5] + " blob, " +
FIELD[6] + " blob, " +
FIELD[7] + " text, " +
FIELD[8] + " text " +
");";
}
}
現在這種設計風格與我的過去數據的基礎上完美地工作,現在是逐字逐句減去作業表擴展DataTable的事實,以便於由於抽象而創建初始數據庫。
任何人都可以看到有什麼不對嗎?
編輯::
我閱讀源的錯誤(SQLiteDatabase.findEditTable()
),似乎這個問題它有表中沒有任何數據。如果是這種情況,我應該得到一個空的遊標返回不應該?或者我誤解了我正在閱讀的內容,並且確實表示無法找到表格?
您是否檢查過設備上實際存在的表格?當我在實際創建表之前嘗試訪問表時,我自己前一陣發現了這個問題。 – stealthcopter 2011-03-02 21:20:50
不幸的是,我只是取消了我的手機,因此我無法很快得到確認。但我確實在SQL.helper類中放置了日誌標記,以便在數據庫創建時檢查進度。這似乎是可以接受的。我會仔細看看。 – AedonEtLIRA 2011-03-02 21:48:18
是的,所有的表格的確是創建的。 – AedonEtLIRA 2011-03-03 16:28:28