我正在尝试使用iCal4J创建一个ics文件。
我按照此页面中开发人员提供的示例进行操作:Example iCal4J
然后我做了这段代码:
时区取自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:user@mail.es"));
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);
但是当我启动它时,应用程序崩溃了,在行中:
TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry();
鉴于此错误:
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)
我第一次考虑构建路径......等等 但我认为一切都还可以。
有办法解决吗?
答案 0 :(得分:1)
您至少缺少一个依赖关系( backport-util-concurrent )
我建议使用gradle或maven来修复依赖树,并节省您将来搜索此类错误的时间。如果您愿意使用它,并且使您的项目更小,更容易在多个工作站上进行管理,那么适当的依赖关系管理软件可以节省您的时间,除了它更容易与VCS一起使用。当然,gradle在Android Studio中是默认的。