我正在尝试制作日历,但我遇到了一些问题。我有我需要的所有信息,如日,月,小时等,但是当我尝试创建日历时,它说应用程序突然停止了。当我调试并查看LogCat时,返回的错误是:“无法找到日历的提供者信息”,它出现在Checkpoint2和Checkpoint3之间。
当我拥有所有信息时创建事件的代码是下一个:
private void crear()
{
Log.d("Crear Evento","Checkpoint 1");
this.alarm = 1; //ALARMA!!!!
Calendar cal = new GregorianCalendar(this.anyo,this.mes,this.dia,this.hora,this.minutos,0);
long startTime = cal.getTimeInMillis();
long endTime = startTime+3600000;
ContentResolver contentResolver = this.getContentResolver();
ContentValues event = new ContentValues();
Log.d("Crear Evento","Checkpoint 2");
Uri eventsUri = Uri.parse(getCalendarUriBase(this)+"events");
Cursor cursor = contentResolver.query(Uri.parse(getCalendarUriBase(this) ),new String[] { "calendar_id", "displayname" }, null,null, null);
Log.d("Crear Evento","Checkpoint 3");
cursor.moveToFirst();
// fetching calendars name
String CNames[] = new String[cursor.getCount()];
// fetching calendars id
int[] CalIds = new int[cursor.getCount()];
Log.d("Crear Evento","Checkpoint 4");
for (int i = 0; i < CNames.length; i++) {
CalIds[i] = cursor.getInt(0);
CNames[i] = cursor.getString(1);
cursor.moveToNext();
}
Log.d("Crear Evento","Cálculos previos sin problemas");
event.put("calendar_id", String.valueOf(CalIds[0]));
event.put("title", this.titulo);
event.put("description", this.descripcion);
event.put("eventLocation", this.lugar);
event.put("allDay", 0);
event.put("eventStatus", 1);
event.put("transparency", 0);
event.put("dtstart", startTime);
event.put("dtend", endTime);
event.put("hasAlarm", this.alarm);
try{
contentResolver.insert(eventsUri, event);
}catch(Exception e){
e.printStackTrace();
}
Log.d("Crear Evento", "¡Guardado sin problemas!");
}