Coluna inválida Contact_ID ContactsContract.Contacts

Eu estou tentando o código a seguir para detalhes de contato AutoComplete como o usuário digita para meu aplicativo android.

public class MakePayment extends Activity {
    private AutoCompleteTextView mAuto;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.makepayment);

        mAuto = (AutoCompleteTextView)findViewById(R.id.autoCompleteTextViewTest);
        ContentResolver content = getContentResolver();
        Cursor cursor = content.query(ContactsContract.Contacts.CONTENT_URI,
                PEOPLE_PROJECTION, null, null, null);

        ContactListAdapter adapter = new ContactListAdapter(this, cursor);
        mAuto.setAdapter(adapter);
    }

     public static class ContactListAdapter extends CursorAdapter implements Filterable {
            public ContactListAdapter(Context context, Cursor c) {
                super(context, c);
                mContent = context.getContentResolver();
            }

            @Override
            public View newView(Context context, Cursor cursor, ViewGroup parent) {
                 final LayoutInflater inflater = LayoutInflater.from(context);
                    final TextView view = (TextView) inflater.inflate(
                            android.R.layout.simple_dropdown_item_1line, parent, false);
                    view.setText(cursor.getString(3));
                    return view;
            }        

            @Override
            public void bindView(View view, Context context, Cursor cursor) {
                ((TextView) view).setText(cursor.getString(3));

            }

            @Override
            public String convertToString(Cursor cursor) {
                return cursor.getString(3);
            }

            @Override
            public Cursor runQueryOnBackgroundThread(CharSequence constraint) {
                if (getFilterQueryProvider() != null) {
                    return getFilterQueryProvider().runQuery(constraint);
                }

                StringBuilder buffer = null;
                String[] args = null;
                if (constraint != null) {
                    buffer = new StringBuilder();
                    buffer.append("UPPER(");
                    buffer.append(ContactsContract.Contacts.DISPLAY_NAME);
                    buffer.append(") GLOB ?");
                    args = new String[] { constraint.toString().toUpperCase() + "*" };
                }

                return mContent.query(ContactsContract.Contacts.CONTENT_URI, PEOPLE_PROJECTION,
                        buffer == null ? null : buffer.toString(), args,
                        null);
            }

            private ContentResolver mContent;           
        }

     private static final String[] PEOPLE_PROJECTION = new String[] {
            ContactsContract.CommonDataKinds.Phone.CONTACT_ID,
            ContactsContract.CommonDataKinds.Phone.NUMBER,
            ContactsContract.CommonDataKinds.Email.DATA,
            ContactsContract.Contacts.DISPLAY_NAME,
        };

}

Mas meu aplicativo é encerrado com os seguintes erros:

06-21 10:33:26.970: E/AndroidRuntime(31086): FATAL EXCEPTION: main
06-21 10:33:26.970: E/AndroidRuntime(31086): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.MyApp/com.MyApp.MakePayment}: java.lang.IllegalArgumentException: Invalid column contact_id
06-21 10:33:26.970: E/AndroidRuntime(31086):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1713)
06-21 10:33:26.970: E/AndroidRuntime(31086):    at android.app.ActivityThread.startActivityNow(ActivityThread.java:1541)
06-21 10:33:26.970: E/AndroidRuntime(31086):    at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
06-21 10:33:26.970: E/AndroidRuntime(31086):    at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
06-21 10:33:26.970: E/AndroidRuntime(31086):    at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:696)
06-21 10:33:26.970: E/AndroidRuntime(31086):    at android.widget.TabHost.setCurrentTab(TabHost.java:328)
06-21 10:33:26.970: E/AndroidRuntime(31086):    at android.widget.TabHost$2.onTabSelectionChanged(TabHost.java:134)
06-21 10:33:26.970: E/AndroidRuntime(31086):    at android.widget.TabWidget$TabClickListener.onClick(TabWidget.java:518)
06-21 10:33:26.970: E/AndroidRuntime(31086):    at android.view.View.performClick(View.java:2485)
06-21 10:33:26.970: E/AndroidRuntime(31086):    at android.view.View$PerformClick.run(View.java:9089)
06-21 10:33:26.970: E/AndroidRuntime(31086):    at android.os.Handler.handleCallback(Handler.java:587)
06-21 10:33:26.970: E/AndroidRuntime(31086):    at android.os.Handler.dispatchMessage(Handler.java:92)
06-21 10:33:26.970: E/AndroidRuntime(31086):    at android.os.Looper.loop(Looper.java:130)
06-21 10:33:26.970: E/AndroidRuntime(31086):    at android.app.ActivityThread.main(ActivityThread.java:3906)
06-21 10:33:26.970: E/AndroidRuntime(31086):    at java.lang.reflect.Method.invokeNative(Native Method)
06-21 10:33:26.970: E/AndroidRuntime(31086):    at java.lang.reflect.Method.invoke(Method.java:507)
06-21 10:33:26.970: E/AndroidRuntime(31086):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:840)
06-21 10:33:26.970: E/AndroidRuntime(31086):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:598)
06-21 10:33:26.970: E/AndroidRuntime(31086):    at dalvik.system.NativeStart.main(Native Method)
06-21 10:33:26.970: E/AndroidRuntime(31086): Caused by: java.lang.IllegalArgumentException: Invalid column contact_id
06-21 10:33:26.970: E/AndroidRuntime(31086):    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:167)
06-21 10:33:26.970: E/AndroidRuntime(31086):    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:137)
06-21 10:33:26.970: E/AndroidRuntime(31086):    at android.content.ContentProviderProxy.bulkQueryInternal(ContentProviderNative.java:372)
06-21 10:33:26.970: E/AndroidRuntime(31086):    at android.content.ContentProviderProxy.query(ContentProviderNative.java:408)
06-21 10:33:26.970: E/AndroidRuntime(31086):    at android.content.ContentResolver.query(ContentResolver.java:266)
06-21 10:33:26.970: E/AndroidRuntime(31086):    at com.MyApp.MakePayment.onCreate(MakePayment.java:28)
06-21 10:33:26.970: E/AndroidRuntime(31086):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-21 10:33:26.970: E/AndroidRuntime(31086):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1677)

Diz coluna inválida contacts_id . Estou fazendo algo errado aqui?

0

1 Respostas

usar

 Cursor cursor = content.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
                PEOPLE_PROJECTION, null, null, null);

ao invés de

 Cursor cursor = content.query(ContactsContract.Contacts.CONTENT_URI,
                PEOPLE_PROJECTION, null, null, null);

and see docs for ContactsContract.Contacts CONTACT_ID,NUMBER,DATA and DISPLAY_NAME is not filed of ContactsContract.Contacts these all are in ContactsContract.CommonDataKinds

0
adicionado
Eu mudei a coluna _ID. Agora, carrega a página, mas ela não é filtrada quando o usuário digita o nome do contato. Alguma sugestão porque?
adicionado o autor gsb, fonte
Eu mudei o URI. Mas ainda assim, os contatos não são carregados quando eu começo a digitar o nome do contato.
adicionado o autor gsb, fonte
veja minha edição answer.this pode ajudar você
adicionado o autor ρяσѕρєя K, fonte