Android Calendar. -


i have problem adding entry calendar.i tried lot of tests without success.

source code:

 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());             }               } } 

errors:

04-11 20:37:27.965: error/contentvalues(262): cannot parse long value 11/04/2011 08:37 @ key dtstart 04-11 20:37:27.995: error/databaseutils(262): writing exception parcel 04-11 20:37:27.995: error/databaseutils(262): java.lang.nullpointerexception 04-11 20:37:27.995: error/databaseutils(262):     @ com.android.providers.calendar.calendarprovider2.calculatelastdate(calendarprovider2.java:2433) 04-11 20:37:27.995: error/databaseutils(262):     @ com.android.providers.calendar.calendarprovider2.updatelastdate(calendarprovider2.java:2502) 04-11 20:37:27.995: error/databaseutils(262):     @ com.android.providers.calendar.calendarprovider2.insertintransaction(calendarprovider2.java:1792) 04-11 20:37:27.995: error/databaseutils(262):     @ com.android.providers.calendar.sqlitecontentprovider.insert(sqlitecontentprovider.java:90) 04-11 20:37:27.995: error/databaseutils(262):     @ android.content.contentprovider$transport.insert(contentprovider.java:180) 04-11 20:37:27.995: error/databaseutils(262):     @ android.content.contentprovidernative.ontransact(contentprovidernative.java:175) 04-11 20:37:27.995: error/databaseutils(262):     @ android.os.binder.exectransact(binder.java:288) 04-11 20:37:27.995: error/databaseutils(262):     @ dalvik.system.nativestart.run(native method) 

start , end time need longs , not strings:

event.put("dtstart", starttime ); event.put("dtend", endtime); 

as try put in "11/04/2011", parsing long fails , exception.

try passing in longs:

long = system.currenttimemillis(); event.put("dtend",now); 

Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -