crash - Android exception while adding calendar -
i'm facing strange problem when i'm trying add calendar contentprovider,
it works there 1 device i'm testing on , doesn't - got crash. device: tablet android 4.0.4 (api15).
some of code:
private static uri buildcaluri() { return calendarcontract.calendars.content_uri.buildupon() .appendqueryparameter(calendarcontract.caller_is_syncadapter, "true") .appendqueryparameter(calendars.account_name, account_name) .appendqueryparameter(calendars.account_type, account_type).build(); } private static contentvalues buildcontentvalues(calendardata cd) { string dispname = cd.getname(); string intname = int_name_prefix + dispname; final contentvalues cv = new contentvalues(); cv.put(calendars.account_name, account_name); cv.put(calendars.account_type, account_type); cv.put(calendars.name, intname); cv.put(calendars.calendar_display_name, dispname); cv.put(calendars.calendar_access_level, calendars.cal_access_none ); cv.put(calendars.owner_account, account_name); cv.put(calendars.visible, cd.isvisible() ? 1 : 0 ); cv.put(calendars.sync_events, 1 ); return cv; } public static long addcalendar(context context, final calendardata cd, final contentresolver cr) { if (cd == null) throw new illegalargumentexception(); /* * on android < 4.1 create account our calendars. using account_type_local * cause these bugs: * * - on android < 4.1: selecting "calendars sync" in calendar app crashes * nullpointerexception. see http://code.google.com/p/android/issues/detail?id=27474 * * - on android <= 2.3: opening calendar app ask create account first * when local calendars present */ long calid; // add calendar final contentvalues cv = buildcontentvalues(cd); uri uri = cr.insert( buildcaluri(), cv ); calid = long.parselong( uri.getlastpathsegment() ); return calid; }
and got:
e/androidruntime( 3221): fatal exception: asynctask #3 e/androidruntime( 3221): java.lang.runtimeexception: error occured while executing doinbackground() e/androidruntime( 3221): @ android.os.asynctask$3.done(asynctask.java:278) e/androidruntime( 3221): @ java.util.concurrent.futuretask$sync.innersetexception(futuretask.java:273) e/androidruntime( 3221): @ java.util.concurrent.futuretask.setexception(futuretask.java:124) e/androidruntime( 3221): @ java.util.concurrent.futuretask$sync.innerrun(futuretask.java:307) e/androidruntime( 3221): @ java.util.concurrent.futuretask.run(futuretask.java:137) e/androidruntime( 3221): @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1076) e/androidruntime( 3221): @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:569) e/androidruntime( 3221): @ java.lang.thread.run(thread.java:856) e/androidruntime( 3221): caused by: java.lang.nullpointerexception e/androidruntime( 3221): @ android.os.parcel.readexception(parcel.java:1333) e/androidruntime( 3221): @ android.database.databaseutils.readexceptionfromparcel(databaseutils.java:182) e/androidruntime( 3221): @ android.database.databaseutils.readexceptionfromparcel(databaseutils.java:136) e/androidruntime( 3221): @ android.content.contentproviderproxy.insert(contentprovidernative.java:415) e/androidruntime( 3221): @ android.content.contentresolver.insert(contentresolver.java:733) e/androidruntime( 3221): @ com.my.app.calendarmapper.addcalendar(calendarmapper.java:128)
line 128 calendarmapper is: uri uri = cr.insert( buildcaluri(), cv );
and don't know can cause exeption.. ideas ?
thanks in advance!
you need use asyctask this. please show code.
Comments
Post a Comment