我正在努力改进我之前为我的应用编写的数据库。以前的数据库工作正常,但只是凌乱,我做了愚蠢的事情,尝试清理它。这导致了一个奇怪的不太有用的错误,我无法开始破译。经过多次回溯并最终返回并让数据库看起来,据我所知,与我以前的数据库相同,我仍然得到了被诅咒的错误。
错误:
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());
这一切似乎都是正确的。使用该服务,我获得数据库,并使用数据库从Table作业中获取所有记录。
getRecord方法步进器和Jobs表定义:
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 " +
");";
}
}
现在这种设计风格与我的上一个数据库完美配合,现在一字不漏,减去了job表扩展DataTable以便于初始数据库创建的事实。
有人可以看到这个有什么问题吗?
EDIT ::
我读了错误的来源(SQLiteDatabase.findEditTable()
),似乎问题是表中没有数据。如果是这种情况我应该得到一个null Cursor返回不应该吗?或者我是否误解了我正在阅读的内容并且它确实说无法找到该表?
答案 0 :(得分:-1)
好的,我发现了什么问题。无效表异常隐藏了一个错误,表明数据库已正确创建。我的坏:P
编辑::这是一个抽象问题。由于我从DataTables扩展但是静态调用变量,因此它从未正确初始化。经验教训:不要对表使用抽象类。除了非常丑陋之外,它也不起作用。