AedonEtLIRA AedonEtLIRA - 21 days ago 5
Android Question

Does anyone know what a Invalid tables exception is?

I'm working on refining a database that I wrote for my app while ago. The previous database worked fine, but was just messy and I did the stupid thing, try and clean it. This has caused a weird less than helpful error that I can't begin to decipher. After much back tracking and finally coming back and having the database look, as far as I can tell, identical to my previous DB, I am still getting the cursed error.

The error:

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)


So naturally I followed the saw trace and saw that it originated from a call I make in one of my activities to the database I have saved in my service (naturally).

The database call from the activity:

Cursor c = mService.getDatabase().getRecord(new Table.Jobs());


This all seems correct. Using the service I get the database, and with the database get all records from the Table jobs.

The getRecord method stepper and the Jobs table definition:

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


And the Table:

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


Now this style of design worked perfectly with my last data base and is now word for word minus the fact that the jobs table extends DataTable for ease of the initial database creation due to abstraction.

Can anyone see anything wrong with this?

EDIT::

I read the source for the error (
SQLiteDatabase.findEditTable()
) and it seems that the issue it that there is no data in the table. If that were the case I should get a null Cursor return shouldn't I? Or am I misinterpreting what I'm reading and it really says that the table can't be found?

Answer

Ok, I found out what was wrong. The Invalid tables exception was hiding an error saying the database was created correctly. My bad :P

EDIT:: It was an abstraction issue. Since I extended from DataTables but was calling the variable statically, it never properly initialized. The lesson: don't use abstract classes for tables. Aside from it being very ugly, it doesn't work as well.