0

我收到了这个错误

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

1 回答 1

2

我已经删除了不推荐使用的类变量和方法。还用新的类替换了它们。检查下面的代码,让我知道它是否能解决您的问题。

import android.provider.ContactsContract.CommonDataKinds;

public class AutoMultipleContacts extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Cursor peopleCursor = getContentResolver().query(CommonDataKinds.Phone.CONTENT_URI,
            PEOPLE_PROJECTION, null, null, CommonDataKinds.Phone.CONTACT_ID);
    ContactListAdapter contactadapter = new ContactListAdapter(this,
            peopleCursor);

    MultiAutoCompleteTextView textView = (MultiAutoCompleteTextView) findViewById(R.id.contacts);
    textView.setAdapter(contactadapter);
    textView.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
}

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)+"<"+cursor.getString(3)+">");
        return view;
    }

    @Override
    public void bindView(View view, Context context, Cursor cursor) {
        ((TextView) view).setText(cursor.getString(5)+"<"+cursor.getString(3)+">");
    }

    @Override
    public String convertToString(Cursor cursor) {
        return cursor.getString(5)+"<"+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(CommonDataKinds.Phone.DISPLAY_NAME);
            buffer.append(") GLOB ?");
            args = new String[] { constraint.toString().toUpperCase() + "*" };
        }

        return mContent.query(CommonDataKinds.Phone.CONTENT_URI, PEOPLE_PROJECTION,
                buffer == null ? null : buffer.toString(), args,
                        CommonDataKinds.Phone.CONTACT_ID);
    }

    private ContentResolver mContent;        
}

private static final String[] PEOPLE_PROJECTION = new String[] {
    CommonDataKinds.Phone._ID,
    CommonDataKinds.Phone.CONTACT_ID,
    CommonDataKinds.Email.TYPE,
    CommonDataKinds.Phone.NUMBER,
    CommonDataKinds.Phone.LABEL,
    CommonDataKinds.Phone.DISPLAY_NAME,
};

}
于 2013-08-20T18:14:37.403 回答