gpt4 book ai didi

android - Contact_ID 列无效 ContactsContract.Contacts

转载 作者:太空狗 更新时间:2023-10-29 15:55:42 25 4
gpt4 key购买 nike

我正在尝试使用以下代码在用户为我的 android 应用键入时AutoComplete 联系人详细信息。

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,
};

}

但是我的应用程序关闭并出现以下错误:

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)

它说 contacts_id 列无效。我在这里做错了什么吗?

最佳答案

使用

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

代替

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

并查看 ContactsContract.Contacts 的文档CONTACT_ID、NUMBER、DATA 和 DISPLAY_NAME 不是 ContactsContract.Contacts 的文件,这些都在 ContactsContract.CommonDataKinds

关于android - Contact_ID 列无效 ContactsContract.Contacts,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11143740/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com