Reputation: 7936
I'm trying to create a ics file with iCal4J.
I follow the examples given by the developer in this page: Example iCal4J
Then I did this code:
The timezone is taken from http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
//Create a TimeZone...
TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry();
TimeZone timezone = registry.getTimeZone("Europe/Madrid");
VTimeZone tz = timezone.getVTimeZone();
Calendar startDate = new GregorianCalendar();
startDate.setTimeZone(timezone);
//Start Date...
if(log)
Log.d("CALENDAR iCAL", "Start Date");
startDate.set(Calendar.DAY_OF_MONTH, Integer.parseInt(date_begin[0]));
startDate.set(Calendar.MONTH, Integer.parseInt(date_begin[1]));
startDate.set(Calendar.YEAR, Integer.parseInt(date_begin[2]));
startDate.set(Calendar.HOUR_OF_DAY,Integer.parseInt(hour_begin[0]));
startDate.set(Calendar.MINUTE, Integer.parseInt(hour_begin[1]));
startDate.set(Calendar.SECOND, 0);
//End Date...
if(log)
Log.d("CALENDAR iCAL", "End date");
Calendar endDate = new GregorianCalendar();
endDate.setTimeZone(timezone);
endDate.set(Calendar.DAY_OF_MONTH, Integer.parseInt(date_end[0]));
endDate.set(Calendar.MONTH, Integer.parseInt(date_end[1]));
endDate.set(Calendar.YEAR, Integer.parseInt(date_end[2]));
endDate.set(Calendar.HOUR_OF_DAY, Integer.parseInt(hour_begin[0]));
endDate.set(Calendar.MINUTE, Integer.parseInt(hour_begin[1]));
endDate.set(Calendar.SECOND, 0);
//Create the event...
if(log)
Log.d("CALENDAR iCAL", "creando evento");
String eventName = subject.toString();
DateTime start = new DateTime(startDate.getTime());
DateTime end = new DateTime(endDate.getTime());
VEvent meeting = new VEvent(start, end, eventName);
Location locat = new Location();
locat.setValue(location.toString());
meeting.getProperties().add(locat);
//add timezone info...
if(log)
Log.d("CALENDAR iCAL", "añadiendo timezone");
meeting.getProperties().add(tz.getTimeZoneId());
//generate unique identifier...
UidGenerator ug;
try {
if(log)
Log.d("CALENDAR iCAL", "generando uid");
ug = new UidGenerator("uidGen");
Uid uid = ug.generateUid();
meeting.getProperties().add(uid);
} catch (SocketException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//Add attendees...
//TODO: en un bucle para añadir todos
if(log)
Log.d("CALENDAR iCAL", "añadiendo un participante");
Attendee dev1 = new Attendee(URI.create("mailto:[email protected]"));
dev1.getParameters().add(Role.REQ_PARTICIPANT);
// dev1.getParameters().add(new Cn("Developer 1"));
meeting.getProperties().add(dev1);
//Create a calendar...
if(log)
Log.d("CALENDAR iCAL", "creando el icsCalendar");
net.fortuna.ical4j.model.Calendar icsCalendar = new net.fortuna.ical4j.model.Calendar();
icsCalendar.getProperties().add(new ProdId("-//Events Calendar//iCal4j 1.0//EN"));
icsCalendar.getProperties().add(CalScale.GREGORIAN);
//Add the event and show in log
icsCalendar.getComponents().add(meeting);
if(log)
Log.d("CALENDAR iCAL","calendario:"+icsCalendar.toString());
//TODO: cambiar por la variable correspondiente
FileOutputStream fout;
try {
if(log)
Log.d("CALENDAR iCAL", "creando el archivo");
fout = new FileOutputStream("NombreReunion"+".ics");
CalendarOutputter outputter = new CalendarOutputter();
outputter.output(icsCalendar, fout);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ValidationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//END CALENDAR ICS
startActivityForResult(intent, REQUEST_CALENDAR);
But when I launch it, the app crashes, in the line:
TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry();
Given this error:
05-18 11:27:07.129: E/AndroidRuntime(23245): FATAL EXCEPTION: main
05-18 11:27:07.129: E/AndroidRuntime(23245): Process: info.guardianproject.otr.app.im, PID: 23245
05-18 11:27:07.129: E/AndroidRuntime(23245): java.lang.NoClassDefFoundError: edu.emory.mathcs.backport.java.util.concurrent.ConcurrentHashMap
05-18 11:27:07.129: E/AndroidRuntime(23245): at net.fortuna.ical4j.model.TimeZoneRegistryImpl.<clinit>(TimeZoneRegistryImpl.java:71)
05-18 11:27:07.129: E/AndroidRuntime(23245): at net.fortuna.ical4j.model.DefaultTimeZoneRegistryFactory.createRegistry(DefaultTimeZoneRegistryFactory.java:48)
05-18 11:27:07.129: E/AndroidRuntime(23245): at info.guardianproject.otr.app.im.app.Meeting$6.onClick(Meeting.java:219)
05-18 11:27:07.129: E/AndroidRuntime(23245): at android.view.View.performClick(View.java:4445)
05-18 11:27:07.129: E/AndroidRuntime(23245): at android.view.View$PerformClick.run(View.java:18446)
05-18 11:27:07.129: E/AndroidRuntime(23245): at android.os.Handler.handleCallback(Handler.java:733)
05-18 11:27:07.129: E/AndroidRuntime(23245): at android.os.Handler.dispatchMessage(Handler.java:95)
05-18 11:27:07.129: E/AndroidRuntime(23245): at android.os.Looper.loop(Looper.java:136)
05-18 11:27:07.129: E/AndroidRuntime(23245): at android.app.ActivityThread.main(ActivityThread.java:5139)
05-18 11:27:07.129: E/AndroidRuntime(23245): at java.lang.reflect.Method.invokeNative(Native Method)
05-18 11:27:07.129: E/AndroidRuntime(23245): at java.lang.reflect.Method.invoke(Method.java:515)
05-18 11:27:07.129: E/AndroidRuntime(23245): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:796)
05-18 11:27:07.129: E/AndroidRuntime(23245): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612)
05-18 11:27:07.129: E/AndroidRuntime(23245): at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
05-18 11:27:07.129: E/AndroidRuntime(23245): at dalvik.system.NativeStart.main(Native Method)
At first time I thought about the build path...etc But I think is everything ok.
Is any way to fix it?
Upvotes: 0
Views: 1000
Reputation: 190
You're missing at least one dependency (backport-util-concurrent)
I recommend using gradle or maven to fix your dependency tree and save you the time to search for such errors in the future. A proper dependency management software can save you hours if you are willing to use it and makes your project smaller and easier to manage on multiple stations, besides its easier to use with a VCS. And of course gradle is default in Android Studio.
Upvotes: 1