У меня на приемнике есть ошибка, но я не могу найти, откуда она!
В моем приложении пользователь может запрограммировать напоминания (уведомления), от x дня до x времени. Итак, у меня есть широковещательный приемник, который отвечает за программирование этих уведомлений при каждом перезапуске телефона.
Ошибка: android.database.sqlite.SQLiteException
Вот код:
DATABASEHANDLER
public List<ReminderClass> getAllReminders() {
List<ReminderClass> reminderList = new ArrayList<>();
String selectQuery = "SELECT * FROM " + TABLE_REMINDERS;
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
try {
if (cursor.moveToFirst()) {
do {
ReminderClass reminderClass = new ReminderClass();
reminderClass.setId(cursor.getInt(cursor.getColumnIndex(KEY_REMINDERS_ID)));
reminderClass.setName(cursor.getString(cursor.getColumnIndex(KEY_REMINDERS_name)));
reminderClass.setDescription(cursor.getString(cursor.getColumnIndex(KEY_REMINDERS_desc2)));
reminderClass.setJours(cursor.getString(cursor.getColumnIndex(KEY_REMINDERS_jours)));
reminderClass.setHeure(cursor.getInt(cursor.getColumnIndex(KEY_REMINDERS_heure)));
reminderClass.setMinute(cursor.getInt(cursor.getColumnIndex(KEY_REMINDERS_minute)));
reminderClass.setEmptyZoneInt(cursor.getInt(cursor.getColumnIndex(KEY_REMINDERS_emptyZoneInt)));
reminderClass.setEmptyZoneStr(cursor.getString(cursor.getColumnIndex(KEY_REMINDERS_emptyZoneStr)));
reminderClass.setShowJours(cursor.getString(cursor.getColumnIndex(KEY_REMINDERS_show)));
reminderClass.setNotifId(cursor.getInt(cursor.getColumnIndex(KEY_REMINDERS_notifId)));
reminderList.add(reminderClass);
} while (cursor.moveToNext());
}
} finally {
cursor.close();
}
return reminderList;
}
ПРИЕМНИК
public void onReceive(Context context, Intent intent) {
List<ReminderClass> remindersList = App.DB().getAllReminders();
if (remindersList != null && !remindersList.isEmpty()) {
for (ReminderClass reminderClass : remindersList) {
int id = reminderClass.getNotifId();
Calendar calender = Calendar.getInstance();
calender.set(Calendar.HOUR_OF_DAY, reminderClass.getHeure());
calender.set(Calendar.MINUTE, reminderClass.getMinute());
calender.set(Calendar.SECOND, 0);
Intent alarmReceiver = new Intent(context, AlarmReceiver2.class);
alarmReceiver.putExtra("reminderId", reminderClass.getId());
alarmReceiver.putExtra("NotificationId", id);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, id, alarmReceiver, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager) context.getSystemService(ALARM_SERVICE);
alarmManager.setExact(AlarmManager.RTC_WAKEUP, calender.getTimeInMillis(), pendingIntent);
setNotification(context, id);
}
}
}
private void setNotification(Context context, int id) {
Calendar calender = Calendar.getInstance();
calender.set(Calendar.HOUR_OF_DAY, 10);
calender.set(Calendar.MINUTE, 0);
calender.set(Calendar.SECOND, 0);
Intent intent = new Intent(context, AlarmReceiverHabit.class);
intent.putExtra("NotificationId", id);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, id, intent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager) context.getSystemService(ALARM_SERVICE);
alarmManager.setExact(AlarmManager.RTC_WAKEUP, calender.getTimeInMillis() + AlarmManager.INTERVAL_DAY, pendingIntent);
}
Манифест EDIT: СООБЩЕНИЕ ОБ ОШИБКЕ ОТ КОНСОЛИ DEV:
Caused by: android.database.sqlite.SQLiteException:
at android.database.sqlite.SQLiteConnection.nativePrepareStatement (Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement (SQLiteConnection.java:1229)
at android.database.sqlite.SQLiteConnection.prepare (SQLiteConnection.java:703)
at android.database.sqlite.SQLiteSession.prepare (SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init> (SQLiteProgram.java:59)
at android.database.sqlite.SQLiteQuery.<init> (SQLiteQuery.java:37)
at android.database.sqlite.SQLiteDirectCursorDriver.query (SQLiteDirectCursorDriver.java:46)
at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory (SQLiteDatabase.java:1865)
at android.database.sqlite.SQLiteDatabase.rawQuery (SQLiteDatabase.java:1804)
at com.com.treasureapp.WorkApp.DatabaseHandler.getAllReminders (DatabaseHandler.java:340)
at com.com.treasureapp.Receiver.AlarmReceiverHabit.onReceive (AlarmReceiverHabit.java:20)
at android.app.ActivityThread.handleReceiver (ActivityThread.java:3614)