DBHelper is the database helper class that creates the database. It has a method getTimetable that returns a Timetable object. when I use it in the main activity it works fine and returns the proper Timetable object. I pass in (this) as a context parameter when creating DBhelper. But when I'm trying to run it in the widget updateAppWidget method it crashes the system I think it happens that I dont pass the same context as I did in the main activity.
static void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId) {
String daysFull[] = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
DBHelper myDB = new DBHelper(context);
Timetable t = myDB.getTimetable();
//t.getTimeSlot(daysFull[Calendar.DAY_OF_WEEK],(new Date()).getHours()+":00")
TimeSlot ts = null;
String text = "";
System.out.print(t.toString());
if (t != null) {
int hourCount = (new Date()).getHours();
while (hourCount < 22) {
if (t.getTimeSlot(daysFull[Calendar.DAY_OF_WEEK], hourCount + ":00") != null) {
ts = t.getTimeSlot(daysFull[Calendar.DAY_OF_WEEK], (new Date()).getHours() + ":00");
break;
}
hourCount++;
}
System.out.println("hello hello hello");
if (ts != null) {
text = ts.getStartTime() + "\n" + ts.getModule() + "\n" + ts.getRoomNumber();
} else {
text = "No More Classes\nFor Today";
}
}
Aucun commentaire:
Enregistrer un commentaire