gpt4 book ai didi

安卓日历。

转载 作者:太空宇宙 更新时间:2023-11-03 13:37:06 25 4
gpt4 key购买 nike

我在向日历添加条目时遇到问题。我尝试了很多测试但没有成功。

源代码:

 String calName; 
String calId = null;
String[] projection = new String[] { "_id", "name" };

Uri calendars = Uri.parse("content://com.android.calendar/calendars");
Cursor managedCursor = managedQuery(calendars, projection, "selected=1", null, null);
ContentValues event = new ContentValues();

DateFormat date = new SimpleDateFormat("dd/MM/yyyy hh:mm");
long time = System.currentTimeMillis();
String StartTime = date.format(time);
String EndTime = "13/4/2011 15:30";

Log.d(TAG, "Value of timeStr: " + StartTime);



if (managedCursor.moveToFirst()) {

int nameColumn = managedCursor.getColumnIndex("name");
int idColumn = managedCursor.getColumnIndex("_id");

do{
calName = managedCursor.getString(nameColumn);
calId = managedCursor.getString(idColumn);

event.put("calendar_id", calId);
event.put("title", "Event Title");
event.put("description", "Description");
event.put("eventLocation", "New York");
event.put("dtstart", StartTime );
event.put("dtend", EndTime);

Uri eventsUri = Uri.parse("content://com.android.calendar/events");
Uri calUri = getContentResolver().insert(eventsUri, event);
}
while (managedCursor.moveToNext());
}
}
}

错误:

04-11 20:37:27.965: ERROR/ContentValues(262): Cannot parse Long value for 11/04/2011 08:37 at key dtstart
04-11 20:37:27.995: ERROR/DatabaseUtils(262): Writing exception to parcel
04-11 20:37:27.995: ERROR/DatabaseUtils(262): java.lang.NullPointerException
04-11 20:37:27.995: ERROR/DatabaseUtils(262): at com.android.providers.calendar.CalendarProvider2.calculateLastDate(CalendarProvider2.java:2433)
04-11 20:37:27.995: ERROR/DatabaseUtils(262): at com.android.providers.calendar.CalendarProvider2.updateLastDate(CalendarProvider2.java:2502)
04-11 20:37:27.995: ERROR/DatabaseUtils(262): at com.android.providers.calendar.CalendarProvider2.insertInTransaction(CalendarProvider2.java:1792)
04-11 20:37:27.995: ERROR/DatabaseUtils(262): at com.android.providers.calendar.SQLiteContentProvider.insert(SQLiteContentProvider.java:90)
04-11 20:37:27.995: ERROR/DatabaseUtils(262): at android.content.ContentProvider$Transport.insert(ContentProvider.java:180)
04-11 20:37:27.995: ERROR/DatabaseUtils(262): at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:175)
04-11 20:37:27.995: ERROR/DatabaseUtils(262): at android.os.Binder.execTransact(Binder.java:288)
04-11 20:37:27.995: ERROR/DatabaseUtils(262): at dalvik.system.NativeStart.run(Native Method)

最佳答案

开始和结束时间必须是长整数而不是字符串:

event.put("dtstart", StartTime );
event.put("dtend", EndTime);

当您尝试输入“11/04/2011”时,将其解析为 long 失败并出现异常。

尝试传入多头:

long now = System.currentTimeMillis();
event.put("dtend",now);

关于安卓日历。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5625865/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com