0

I am using the library ActiveAndroid to use the database, but when I try to save an object, it says that there is no such table. I've tried updating the database version and uninstalling my application, but still no luck. Any help will be appreciated. Thank you!

These is the error:

11-29 05:16:11.048: E/SQLiteLog(3170): (1) no such table: alarm
11-29 05:16:11.048: E/SQLiteDatabase(3170): Error inserting weekly=1 isOnSnooze=0 tone=Default ringtone (Cesium) thursday=1 monday=1 alarmId=0 hour=0 snoozeTime=0 isEnabled=1 minute=0 wednesday=1 sunday=1 name=Untitled saturday=1 tuesday=1 friday=1
11-29 05:16:11.048: E/SQLiteDatabase(3170): android.database.sqlite.SQLiteException: no such table: alarm (code 1): , while compiling: INSERT INTO alarm(weekly,isOnSnooze,tone,thursday,monday,alarmId,hour,snoozeTime,isEnabled,minute,wednesday,sunday,name,saturday,tuesday,friday) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
11-29 05:16:11.048: E/SQLiteDatabase(3170):     at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
11-29 05:16:11.048: E/SQLiteDatabase(3170):     at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
11-29 05:16:11.048: E/SQLiteDatabase(3170):     at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
11-29 05:16:11.048: E/SQLiteDatabase(3170):     at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
11-29 05:16:11.048: E/SQLiteDatabase(3170):     at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
11-29 05:16:11.048: E/SQLiteDatabase(3170):     at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
11-29 05:16:11.048: E/SQLiteDatabase(3170):     at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1467)
11-29 05:16:11.048: E/SQLiteDatabase(3170):     at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1339)
11-29 05:16:11.048: E/SQLiteDatabase(3170):     at com.activeandroid.Model.save(Model.java:153)
11-29 05:16:11.048: E/SQLiteDatabase(3170):     at com.martyawesome.smartyalarm.activities.AddAlarmActivity.saveAlarm(AddAlarmActivity.java:254)
11-29 05:16:11.048: E/SQLiteDatabase(3170):     at com.martyawesome.smartyalarm.activities.AddAlarmActivity_$1.onClick(AddAlarmActivity_.java:62)
11-29 05:16:11.048: E/SQLiteDatabase(3170):     at android.view.View.performClick(View.java:4438)
11-29 05:16:11.048: E/SQLiteDatabase(3170):     at android.view.View$PerformClick.run(View.java:18422)
11-29 05:16:11.048: E/SQLiteDatabase(3170):     at android.os.Handler.handleCallback(Handler.java:733)
11-29 05:16:11.048: E/SQLiteDatabase(3170):     at android.os.Handler.dispatchMessage(Handler.java:95)
11-29 05:16:11.048: E/SQLiteDatabase(3170):     at android.os.Looper.loop(Looper.java:136)
11-29 05:16:11.048: E/SQLiteDatabase(3170):     at android.app.ActivityThread.main(ActivityThread.java:5001)
11-29 05:16:11.048: E/SQLiteDatabase(3170):     at java.lang.reflect.Method.invokeNative(Native Method)
11-29 05:16:11.048: E/SQLiteDatabase(3170):     at java.lang.reflect.Method.invoke(Method.java:515)
11-29 05:16:11.048: E/SQLiteDatabase(3170):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
11-29 05:16:11.048: E/SQLiteDatabase(3170):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
11-29 05:16:11.048: E/SQLiteDatabase(3170):     at dalvik.system.NativeStart.main(Native Method)
11-29 05:16:11.060: D/dalvikvm(3170): GC_FOR_ALLOC freed 1942K, 33% free 9905K/14608K, paused 4ms, total 4ms
11-29 05:16:11.080: E/MediaPlayer(3170): Should have subtitle controller already set

Here are my codes:

AlarmModel.java (GenericModel extends com.activeandroid.Model; it just contains th CRUD operations)

package com.martyawesome.smartyalarm.models;

import java.util.List;

import com.activeandroid.annotation.Column;
import com.activeandroid.annotation.Table;
import com.cmai.al.models.GenericModel;

@Table(name = "alarm")
public class AlarmModel extends GenericModel<Object> {

@Column(name = "alarmId")
public int id;

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

@Column(name = "hour")
public int timeHour;

@Column(name = "minute")
public int timeMinute;

@Column(name = "sunday")
public int sunday;

@Column(name = "monday")
public int monday;

@Column(name = "tuesday")
public int tuesday;

@Column(name = "wednesday")
public int wednesday;

@Column(name = "thursday")
public int thursday;

@Column(name = "friday")
public int friday;

@Column(name = "saturday")
public int saturday;

@Column(name = "weekly")
public int repeatWeekly;

@Column(name = "tone")
public String alarmTone;

@Column(name = "isEnabled")
public int isEnabled;

@Column(name = "isOnSnooze")
public int isOnSnooze;

@Column(name = "snoozeTime")
public int snoozeTime;

public List<AlarmModel> getAll() {
    return super.getAll(getCurrentClass());
}

public void update(AlarmModel model) {
    super.update(getCurrentClass(), model);
}

public void updateAll(List<AlarmModel> models) {
    super.updateAll(getCurrentClass(), models);
}

public void deleteAll() {
    super.deleteAll(getCurrentClass());
}

}

AndroidManifest.xml

...
<application android:name="com.activeandroid.app.Application"
...
<meta-data
    android:name="AA_DB_NAME"
    android:value="smartyalarm.db" />
<meta-data
    android:name="AA_DB_VERSION"
    android:value="2" />
</application>

2 Answers2

0

I think your AlarmModel class should extends com.activeandroid.Model, but not the GenericModel<Object>.

romtsn
  • 11,704
  • 2
  • 31
  • 49
  • Ow sorry I forgot to include that the GenericModel extends com.activeandroid.Model. – Marty Hernandez Nov 29 '14 at 05:36
  • What if you change the table name to @Table(name = "Alarms") ? – romtsn Nov 29 '14 at 05:41
  • But what if you change extending to the `com.activeandroid.Model`? I just think that library doesn't supports inheritance as you want. Also what table name your `GenericModel` has? – romtsn Nov 29 '14 at 05:46
  • the GenericModel just contains the methods for retrieving, updating and deleting of models. My error is that my app somehow doesn't save the table for my AlarmModel. – Marty Hernandez Nov 29 '14 at 05:51
  • Your problem is that your table was not created, so it means that is something wrong with your annotations. – romtsn Nov 29 '14 at 05:54
  • I was able to fix my error! It looks like my ActiveAndroid library is outdated. So I downloaded the newest one which is 3.1 and it fixed it! Though, thank you for the time for helping :) – Marty Hernandez Nov 29 '14 at 06:01
  • 1
    Np, I just see that they add inheritance support in newer versions:) – romtsn Nov 29 '14 at 06:02
0

Your Model Class needs to implement Serializable.

Sagar
  • 1
  • While this might be a valuable hint to solve the problem, a good answer also demonstrates the solution. Please [EDIT](http://stackoverflow.com/posts/5419867/edit) to provide example code to show what you mean. Alternatively, consider writing this as a comment instead – ρяσѕρєя K Jan 14 '17 at 04:55
  • you can put this as a comment. Answer requires more clear and nearly exact answer for the question. – Ajith Pandian Jan 14 '17 at 04:55