Database Creation Fails for Single Class
I've been able to get ActiveAndroid working with other classes in my app but one particular class causes the following stack trace.
Caused by: android.database.sqlite.SQLiteException: near "(": syntax error (code 1): , while compiling: CREATE TABLE IF NOT EXISTS (Id INTEGER PRIMARY KEY AUTOINCREMENT);
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1672)
at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1603)
at com.activeandroid.DatabaseHelper.executeCreate(Unknown Source)
at com.activeandroid.DatabaseHelper.onCreate(Unknown Source)
at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:252)
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:164)
at com.activeandroid.Cache.openDatabase(Unknown Source)
at com.activeandroid.Cache.initialize(Unknown Source)
at com.activeandroid.ActiveAndroid.initialize(Unknown Source)
at com.activeandroid.ActiveAndroid.initialize(Unknown Source)
at com.activeandroid.ActiveAndroid.initialize(Unknown Source)
at com.activeandroid.app.Application.onCreate(Unknown Source)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1007)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4444)
at android.app.ActivityThread.access$1300(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
The class definition looks like.
package com.tristanoneil.flashcards;
import com.activeandroid.Model;
import com.activeandroid.annotation.Column;
import com.activeandroid.annotation.Table;
@Table(name = "category")
public class Category extends Model {
@Column(name = "name")
public String name;
}
It seems to me that it's not getting the table name for some reason. Any insight?
Having the same problem, did you figured it out?
Did you declare an empty constructor for your class? From the wiki:
ActiveAndroid uses the standard-constructor of your class to instantiate objects. If you define your own constructors you have to define a parameterless constructor as well.
Just tried declaring an empty constructor, but I get the same error
Are you importing the library via gradle? It is recommendable to build it from scratch or import it directly.