我收到了这个错误
08-20 22:22:54.705: E/AndroidRuntime(15774): FATAL EXCEPTION: main
08-20 22:22:54.705: E/AndroidRuntime(15774): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.john/com.example.john.MainActivity}: android.database.sqlite.SQLiteException: no such column: display_nameASC: , while compiling: SELECT _id, has_phone_number, display_name FROM view_data data WHERE (1 AND mimetype_id=5 AND indicate_phone_or_sim_contact>-2) ORDER BY display_nameASC
08-20 22:22:54.705: E/AndroidRuntime(15774): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2077)
08-20 22:22:54.705: E/AndroidRuntime(15774): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2104)
08-20 22:22:54.705: E/AndroidRuntime(15774): at android.app.ActivityThread.access$600(ActivityThread.java:134)
08-20 22:22:54.705: E/AndroidRuntime(15774): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1247)
08-20 22:22:54.705: E/AndroidRuntime(15774): at android.os.Handler.dispatchMessage(Handler.java:99)
08-20 22:22:54.705: E/AndroidRuntime(15774): at android.os.Looper.loop(Looper.java:154)
08-20 22:22:54.705: E/AndroidRuntime(15774): at android.app.ActivityThread.main(ActivityThread.java:4624)
08-20 22:22:54.705: E/AndroidRuntime(15774): at java.lang.reflect.Method.invokeNative(Native Method)
08-20 22:22:54.705: E/AndroidRuntime(15774): at java.lang.reflect.Method.invoke(Method.java:511)
08-20 22:22:54.705: E/AndroidRuntime(15774): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:809)
08-20 22:22:54.705: E/AndroidRuntime(15774): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576)
08-20 22:22:54.705: E/AndroidRuntime(15774): at dalvik.system.NativeStart.main(Native Method)
08-20 22:22:54.705: E/AndroidRuntime(15774): Caused by: android.database.sqlite.SQLiteException: no such column: display_nameASC: , while compiling: SELECT _id, has_phone_number, display_name FROM view_data data WHERE (1 AND mimetype_id=5 AND indicate_phone_or_sim_contact>-2) ORDER BY display_nameASC
08-20 22:22:54.705: E/AndroidRuntime(15774): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:181)
08-20 22:22:54.705: E/AndroidRuntime(15774): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:137)
08-20 22:22:54.705: E/AndroidRuntime(15774): at android.content.ContentProviderProxy.query(ContentProviderNative.java:358)
08-20 22:22:54.705: E/AndroidRuntime(15774): at android.content.ContentResolver.query(ContentResolver.java:312)
08-20 22:22:54.705: E/AndroidRuntime(15774): at com.example.john.First_Activity.onCreate(First_Activity.java:61)
08-20 22:22:54.705: E/AndroidRuntime(15774): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:801)
08-20 22:22:54.705: E/AndroidRuntime(15774): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1038)
08-20 22:22:54.705: E/AndroidRuntime(15774): at android.app.BackStackRecord.run(BackStackRecord.java:622)
08-20 22:22:54.705: E/AndroidRuntime(15774): at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1396)
08-20 22:22:54.705: E/AndroidRuntime(15774): at android.app.Activity.performStart(Activity.java:4488)
08-20 22:22:54.705: E/AndroidRuntime(15774): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2050)
08-20 22:22:54.705: E/AndroidRuntime(15774): ... 11 more
实际上我编辑了这个站点的代码,因为它已被弃用(https://github.com/novoda/android/blob/master/MultipleContacts/src/com/novoda/AutoMultipleContacts.java),遗憾的是我迷路了。
这是我编辑的版本:
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(5));
return view;
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
((TextView) view).setText(cursor.getString(5));
}
@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.CommonDataKinds.Phone.NUMBER);
buffer.append(") GLOB ?");
args = new String[] { constraint.toString().toUpperCase() + "*" };
}
return mContent.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, PEOPLE_PROJECTION,
buffer == null ? null : buffer.toString(), args,
ContactsContract.Contacts.DISPLAY_NAME);
}
private ContentResolver mContent;
}
private static final String[] PEOPLE_PROJECTION = new String[] {
ContactsContract.Contacts._ID,
ContactsContract.Contacts.DISPLAY_NAME,
ContactsContract.CommonDataKinds.Phone.NUMBER
};