2013-08-20 37 views
0

我得到這個錯誤錯誤:查詢聯繫人數據庫,並將其綁定到multiautocompletetextview

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

回答

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

} 
+0

我試過的代碼,但它似乎有些不妥就可以了。一旦我型有出來一個ListView,但沒有內容吧..它就像一張空白的ListView ..感謝的方式 – RieJack

+0

和當我嘗試在列表視圖上選擇它返回一個數字在multiautocomplete textview ..它返回數字..沒有與它相關的名稱.. – RieJack

+0

你在設備上嘗試它,因爲我在我的設備上測試它,然後聯繫人列表已打開 – Arshu

相關問題