Я использую библиотеку ActiveAndroid для использования базы данных, но при попытке сохранить объект пишет, что такой таблицы нет. Я пытался обновить версию базы данных и удалить свое приложение, но все равно не повезло. Любая помощь будет оценена. Благодарю вас!
Это ошибка:
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
Вот мои коды:
AlarmModel.java (GenericModel расширяет com.activeandroid.Model; он просто содержит операции CRUD)
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>