Hi,

Thanks for your reply.

My code is working now, but I don't know why. I already had the
appropriate permissions as suggested by you. Your suggestion to add
more contacts can't help, since the Uri 'myperson' is not used later
in the code where the exception occurs. So, I'm clueless about why it
didn't work last week.

Thanks, anyway.

Pankaj.



On Aug 27, 1:46 pm, 장영환 <cyberj...@gmail.com> wrote:
> Hi.
> I tried with your code, it works.
> Kindly check two things.
>
> 1. You should over 23 contacts, because you write "Uri myPerson =
> ContentUris.withAppendedId( People.CONTENT_URI, 23 );"
>
> 2. You should write permission code in AndroidManifest.xml like below.
>
>     <uses-permission android:name="android.permission.READ_CONTACTS" />
>     <application android:icon="@drawable/icon" 
> android:label="@string/app_name">
>         <activity android:name=".ContentProviderExamples"
>                   android:label="@string/app_name">
>             <intent-filter>
>
> Have a good day!!
>
> 2009/8/26PankajGodbole <panka...@gmail.com>
>
>
>
> > Hello,
>
> > I am learning about Content Providers, and tried the example from the 
> > official Android tutorial on the topic. Please see the code below:
>
> >  --------------------
>
> > package com.example.devguide;
>
> > import android.app.Activity;
> > import android.content.ContentUris;
> > import android.database.Cursor;
> > import android.net.Uri;
> > import android.os.Bundle;
> > import android.provider.Contacts.People;
> > import android.util.Log;
>
> > public class ContentProviderExamples extends Activity {
> >     /** Called when the activity is first created. */
> >     @Override
> >     public void onCreate(Bundle savedInstanceState) {
> >         super.onCreate(savedInstanceState);
> >         setContentView(R.layout.main);
>
> >         /* Use the ContentUris method to produce the base URI
> >          * for the contact with _ID == 23. */
> >         Uri myPerson = ContentUris.withAppendedId( People.CONTENT_URI, 23 );
>
> >         /* Alternatively, use the Uri method to produce the base URI. */
> >         myPerson = Uri.withAppendedPath( People.CONTENT_URI, "23" );
>
> >         /* Query this particular record. */
> >         Cursor c = managedQuery( myPerson, null, null, null, null );
>
> >         /* Form an array specifying which columns to return. */
> >         String[] projection = new String[] { People._ID,
> >                                              //People._COUNT, //throws 
> > IllegalArgumentException
> >                                              People.NAME,
> >                                              People.NUMBER };
> >         Log.i( "CPE", "projection[] = " + projection );
>
> >         /* Get the base URI for the People table in the Contacts content 
> > provider. */
> >         Uri contacts = People.CONTENT_URI;
>
> >         /* Construct the query. */
> >         Cursor managedCursor = managedQuery( contacts,
> >                                              projection,
> >                                              null,
> >                                              null,
> >                                              People.NAME + " ASC" );
>
> >         showColumnData( managedCursor );
>
> >         Log.i( "CPE", "End of current code" );
>
> >     }
>
> >     private void showColumnData( Cursor c ) {
> >         if ( c.moveToFirst() ) {
> >             String name;
> >             String phoneNumber;
> >             String imagePath;
> >             int nameColumn = c.getColumnIndex( People.NAME );
> >             int phoneColumn = c.getColumnIndex( People.NUMBER );
>
> >             do {
> >                 /* Obtain the field values. */
> >                 name = c.getString( nameColumn );
> >                 phoneNumber = c.getString( phoneColumn );
> >                 Log.d( "CPE", "name = " + name + ", phone = " + phoneNumber 
> > );
>
> >             } while ( c.moveToNext() );
> >         }
> >     }
> > }
>
> > However, the example given did not work, because calling managedQuery with 
> > the array projection as one of the arguments resulted in a 
> > IllegalArgumentException (java.lang.IllegalArgumentException). Android says 
> > that the column "_count" which is the value of the element People._COUNT in 
> > array projection is invalid. Can anyone explain to me the reason for this 
> > exception, even though the names of all the columns are as per the API 
> > specification?
>
> > Please see the output of LogCat below:
>
> > 08-26 12:06:20.330: ERROR/AndroidRuntime(1112): java.lang.RuntimeException: 
> > Unable to start activity 
> > ComponentInfo{com.example.devguide/com.example.devguide.ContentProviderExamples}:
> >  java.lang.IllegalArgumentException: Invalid column _count
>
> > Thanks,
> >PankajGodbole,
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to android-beginners@googlegroups.com
To unsubscribe from this group, send email to
android-beginners-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to