title: Calander in 2.2 unable to query instances > Unknown URL content://com.android.calendar/instances/when
body: <p>Can anyone plese help me with the following code, the problem is with </p>
  
  <pre><code>Uri.Builder builder = Uri.parse("content://com.android.calendar/instances/when").buildUpon();
  </code></pre>
  
  <p>which throws an Unkown URL  illegal argument exception see below </p>
  
  <p>Thanks</p>
  
  <p>Graham </p>
  
  <p>code
      Fetch a list of all calanders, iterate through all calanders using the calander ids </p>
  
  <pre><code>package gb.org;
  
  
  
  
  import java.util.Calendar;
  import java.util.Date;
  import java.util.HashSet;
  
  import android.content.ContentResolver;
  import android.content.ContentUris;
  import android.content.Context;
  import android.database.Cursor;
  import android.net.Uri;
  import android.text.format.DateUtils;
  import android.os.SystemClock;
  
  public class Example {
  
              public static void readCalendar(Context context) {
  
          ContentResolver contentResolver = context.getContentResolver();
  
          // Fetch a list of all calendars synced with the device, their display names and whether the
          // user has them selected for display.
  
          final Cursor cursor = contentResolver.query(Uri.parse("content://com.android.calendar/calendars"),
                   (new String[] { "_id", "displayName", "selected" }), null, null, null); 
  
  
          HashSet&lt;String&gt; calendarIds = new HashSet&lt;String&gt;();
  
  
  
  
          while (cursor.moveToNext()) {
  
              final String _id = cursor.getString(0);
              final String displayName = cursor.getString(1);
              final Boolean selected = !cursor.getString(2).equals("0");
  
              System.out.println("Calendar is " + _id + " Display Name: " + displayName + " Selected: " + selected);
  
              //DETERMINE IF CALENDAR IS SELECTED IF YES THEN USE IT 
  
              calendarIds.add(_id);
          }
  
          // query the instance table         
          for (String id : calendarIds) {
  
              Uri.Builder builder = Uri.parse("content://com.android.calendar/instances/when").buildUpon(); 
  
  
              Cursor eventCursor = contentResolver.query(builder.build(),
                      new String[] { "title", "begin", "end", "allDay"}, "Calendars._id=" + id,
                      null, "startDay ASC, startMinute ASC"); 
  
              while (eventCursor.moveToNext()) {
  
                  long  timeNow=System.currentTimeMillis();  //the current time 
  
                  final String title = eventCursor.getString(0);
                  final long begin = eventCursor.getLong(1);
                  final Date begin_DATE = new Date(begin);
  
                  //final Date end = new Date(eventCursor.getLong(2));
                  final Date nowDATE = new Date(timeNow);
                  final long end = eventCursor.getLong(2);
                  final Date end_DATE = new Date(end);
                  final long allDay = eventCursor.getLong(3);
  
                  //function to check the time 
                   //is there a calendar event today when I run the application 
                   //if yes then print a toast message 
                   //if not then do nothing - maybe a toast do nothing!
                  //Calendar Cnow = Calendar.getInstance();
                  //System.out.println("Calendar now means:" + Cnow.getTimeInMillis());  //time now 
                  if(timeNow &gt;= begin &amp;&amp; timeNow &lt;=end){
                      //check time block for meeting 
                      System.out.println("BLOCK BLOCK BLOCK ");
                      System.out.println("The meeting is: " + title + "begin is " +  begin_DATE + "end is" + end_DATE );
                      //call blocker function 
  
                  }
  
                  else{
                      System.out.println("NO BLOCK NO BLOCK NO BLOCK  ");
                      //stop and restart service return to main screen with dialog box 
                  }
  
  
                  //System.out.println("begin:" + begin  + " End: " + end  + "all day :" + allDay + "time NOW" + timeNow );
                  //assign to variables for begin and end
                  Date d = new Date();
                  //work with time and data               
  
                  //System.out.println("current date" +  d.getDate() + "current hour" + d.getHours() 
                      //  + "current min" + d.getMinutes() + "current second" + d.getSeconds());
              }
          }
      }
  
  
  }
  </code></pre>
  
  <p>EXCEPTION >></p>
  
  <pre><code>&gt; 12-02 14:58:42.097: E/AndroidRuntime(12298): FATAL EXCEPTION: main
  &gt;     12-02 14:58:42.097: E/AndroidRuntime(12298): java.lang.RuntimeException: Unable to start activity
  &gt; ComponentInfo{gb.org/gb.org.main}: java.lang.IllegalArgumentException:
  &gt; Unknown URL content://com.android.calendar/instances/when
  &gt;     12-02 14:58:42.097: E/AndroidRuntime(12298):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
  &gt;     12-02 14:58:42.097: E/AndroidRuntime(12298):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
  &gt;     12-02 14:58:42.097: E/AndroidRuntime(12298):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
  &gt;     12-02 14:58:42.097: E/AndroidRuntime(12298):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
  &gt;     12-02 14:58:42.097: E/AndroidRuntime(12298):  at android.os.Handler.dispatchMessage(Handler.java:99)
  &gt;     12-02 14:58:42.097: E/AndroidRuntime(12298):  at android.os.Looper.loop(Looper.java:123)
  &gt;     12-02 14:58:42.097: E/AndroidRuntime(12298):  at android.app.ActivityThread.main(ActivityThread.java:3687)
  &gt;     12-02 14:58:42.097: E/AndroidRuntime(12298):  at java.lang.reflect.Method.invokeNative(Native Method)
  &gt;     12-02 14:58:42.097: E/AndroidRuntime(12298):  at java.lang.reflect.Method.invoke(Method.java:507)
  &gt;     12-02 14:58:42.097: E/AndroidRuntime(12298):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
  &gt;     12-02 14:58:42.097: E/AndroidRuntime(12298):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
  &gt;     12-02 14:58:42.097: E/AndroidRuntime(12298):  at dalvik.system.NativeStart.main(Native Method)
  &gt;     12-02 14:58:42.097: E/AndroidRuntime(12298): Caused by: java.lang.IllegalArgumentException: Unknown URL
  &gt; content://com.android.calendar/instances/when
  &gt;     12-02 14:58:42.097: E/AndroidRuntime(12298):  at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:144)
  &gt;     12-02 14:58:42.097: E/AndroidRuntime(12298):  at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:114)
  &gt;     12-02 14:58:42.097: E/AndroidRuntime(12298):  at android.content.ContentProviderProxy.bulkQueryInternal(ContentProviderNative.java:330)
  &gt;     12-02 14:58:42.097: E/AndroidRuntime(12298):  at android.content.ContentProviderProxy.query(ContentProviderNative.java:366)
  &gt;     12-02 14:58:42.097: E/AndroidRuntime(12298):  at android.content.ContentResolver.query(ContentResolver.java:262)
  &gt;     12-02 14:58:42.097: E/AndroidRuntime(12298):  at gb.org.Example.readCalendar(Example.java:62)
  &gt;     12-02 14:58:42.097: E/AndroidRuntime(12298):  at gb.org.main.onCreate(main.java:12)
  &gt;     12-02 14:58:42.097: E/AndroidRuntime(12298):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
  &gt;     12-02 14:58:42.097: E/AndroidRuntime(12298):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
  &gt;     12-02 14:58:42.097: E/AndroidRuntime(12298):  ... 11 more
  </code></pre>
  
  <p>MANIFEST</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="gb.org"
        android:versionCode="1"
        android:versionName="1.0"&gt;
  - &lt;application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true"&gt;
  - &lt;activity android:name=".main" android:label="@string/app_name"&gt;
  - &lt;intent-filter&gt;
    &lt;action android:name="android.intent.action.MAIN" /&gt; 
    &lt;category android:name="android.intent.category.LAUNCHER" /&gt; 
    &lt;/intent-filter&gt;
    &lt;/activity&gt;
    &lt;/application&gt;
    &lt;uses-sdk android:minSdkVersion="7" /&gt; 
    &lt;uses-permission android:name="android.permission.READ_CALENDAR" /&gt;
    &lt;android.permission android:name= "android.permission.WRITE_CALENDAR" /&gt;
  
  
    &lt;/manifest&gt;
  </code></pre>