Search code examples
androidactiveandroid

Android app with active android closes on start


I'm building an app with active android orm and I tried running it after creating all my models, and the app stops when i start it.

NOTE: I didnt updated my models and its the first time i run the app after installing active android and creating my models. I also didn't create any instance of a model or saved something to the database.

Logcat:

09-13 13:26:08.789  27599-27599/com.sqvat.squat W/Xposed﹕ Package name for       /data/app/com.zst.xposed.xuimod-1.apk had to be retrieved via parser
09-13 13:26:08.959  27599-27599/com.sqvat.squat D/dalvikvm﹕ JIT code cache reset in 0 ms (0 bytes 3/0)
09-13 13:26:08.969  27599-27599/com.sqvat.squat D/dalvikvm﹕ GC_FOR_ALLOC freed 341K, 45% free 4755K/8504K, paused 17ms, total 17ms
09-13 13:26:09.160  27599-27599/com.sqvat.squat D/dalvikvm﹕ GC_FOR_ALLOC freed 487K, 45% free 4781K/8676K, paused 17ms, total 18ms
09-13 13:26:09.170  27599-27599/com.sqvat.squat E/SQLiteLog﹕ (1) near "Order": syntax error
09-13 13:26:09.170  27599-27599/com.sqvat.squat D/AndroidRuntime﹕ Shutting down VM
09-13 13:26:09.170  27599-27599/com.sqvat.squat W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x415fdba8)
09-13 13:26:09.170  27599-27599/com.sqvat.squat E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.sqvat.squat, PID: 27599
    java.lang.RuntimeException: Unable to create application com.activeandroid.app.Application: android.database.sqlite.SQLiteException: near "Order": syntax error (code 1): , while compiling: CREATE TABLE IF NOT EXISTS CompletedSessions (Id INTEGER PRIMARY KEY AUTOINCREMENT, CompletedWorkout INTEGER REFERENCES CompletedWorkouts(Id) ON DELETE NO ACTION ON UPDATE NO ACTION, Session INTEGER REFERENCES Sessions(Id) ON DELETE NO ACTION ON UPDATE NO ACTION, Order INTEGER);
            at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4389)
            at de.robv.android.xposed.XposedBridge.invokeOriginalMethodNative(Native Method)
            at de.robv.android.xposed.XposedBridge.handleHookedMethod(XposedBridge.java:631)
            at android.app.ActivityThread.handleBindApplication(Native Method)
            at android.app.ActivityThread.access$1500(ActivityThread.java:141)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1262)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5059)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
            at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: android.database.sqlite.SQLiteException: near "Order": syntax error (code 1): , while compiling: CREATE TABLE IF NOT EXISTS CompletedSessions (Id INTEGER PRIMARY KEY AUTOINCREMENT, CompletedWorkout INTEGER REFERENCES CompletedWorkouts(Id) ON DELETE NO ACTION ON UPDATE NO ACTION, Session INTEGER REFERENCES Sessions(Id) ON DELETE NO ACTION ON UPDATE NO ACTION, Order INTEGER);
            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.createTable(DatabaseHelper.java:138)
            at com.activeandroid.DatabaseHelper.onCreate(DatabaseHelper.java:51)
            at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:252)
            at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:164)
            at com.activeandroid.Registry.openDatabase(Registry.java:149)
            at com.activeandroid.Registry.initialize(Registry.java:107)
            at com.activeandroid.ActiveAndroid.initialize(ActiveAndroid.java:8)
            at com.activeandroid.app.Application.onCreate(Application.java:9)
            at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1007)
            at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4386)
            at de.robv.android.xposed.XposedBridge.invokeOriginalMethodNative(Native Method)
            at de.robv.android.xposed.XposedBridge.handleHookedMethod(XposedBridge.java:631)
            at android.app.ActivityThread.handleBindApplication(Native Method)
            at android.app.ActivityThread.access$1500(ActivityThread.java:141)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1262)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5059)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
            at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
            at dalvik.system.NativeStart.main(Native Method)

my 'CompletedSession' model:

package com.sqvat.squat.data;

import com.activeandroid.Model;
import com.activeandroid.annotation.Column;
import com.activeandroid.annotation.Table;

@Table(name = "CompletedSessions")
public class CompletedSession extends Model {

    @Column(name = "Session")
    public Session session;

    @Column(name = "CompletedWorkout")
    public CompletedWorkout completedWorkout;

    @Column(name = "Order")
    public int order;

    public CompletedSession() {
        super();
    }
}

'Session' model:

package com.sqvat.squat.data;

import com.activeandroid.Model;
import com.activeandroid.annotation.Column;
import com.activeandroid.annotation.Table;

@Table(name = "Sessions")
public class Session extends Model {

    @Column(name = "Workout")
    public Workout workout;

    @Column(name = "TargetOrder")
    public int targetOrder;

    @Column(name = "Exercise")
    public Exercise exercise;

    @Column(name = "Rest")
    public int rest;

    public Session() {
        super();
    }
}

and 'CompletedWorkout' model:

package com.sqvat.squat.data;

import com.activeandroid.Model;
import com.activeandroid.annotation.Column;
import com.activeandroid.annotation.Table;
import com.activeandroid.query.Select;

import java.util.List;

@Table(name = "CompletedWorkouts")
public class CompletedWorkout extends Model {

    @Column(name = "Workout")
    public Workout workout;

    @Column(name = "Date")
    public String date;

    public CompletedWorkout(){
        super();
    }

    public static List<CompletedWorkout> getAll() {
        return new Select()
                .from(CompletedWorkout.class)
                .execute();
    }

}

Solution

  • I found the problem: SET and ORDER are Reserved words...