我基本是按照《Android应用开发揭秘》中的例子码的代码package blog.liucc;import android.R.anim;
import android.app.Activity;
import android.database.Cursor;
import android.graphics.Color;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.provider.ContactsContract.PhoneLookup;
import android.text.Layout;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;public class MyCommActivity extends Activity {

private LinearLayout ccLayout;
private ListView ccListView;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        ccLayout = new LinearLayout(this); //Context选this
        ccLayout.setOrientation(LinearLayout.VERTICAL);
        ccLayout.setBackgroundColor(Color.BLACK);
        
        setContentView(ccLayout); //设置外观!
        
        ccListView = new ListView(this); //Context选this
        LinearLayout.LayoutParams ccparmas = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, 
         LinearLayout.LayoutParams.WRAP_CONTENT);
        ccListView.setBackgroundColor(Color.BLACK);
        ccLayout.addView(ccListView, ccparmas);
        
        Cursor ccCursor = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
        startManagingCursor(ccCursor);
        
        ListAdapter ccAdapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_2, ccCursor,
         new String[] {PhoneLookup.DISPLAY_NAME, PhoneLookup.NUMBER}, 
         new int[] {android.R.id.text1, android.R.id.text2});
        ccListView.setAdapter(ccAdapter);      
        
        
    }
}AndroidManifest也做了增加
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="blog.liucc"
    android:versionCode="1"
    android:versionName="1.0" >    <uses-sdk android:minSdkVersion="8" />
       <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".MyCommActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
 <uses-permission android:name="android.permission.READ_CONTACTS"/>
    
</manifest>
结果出现了报错01-31 06:43:14.417: W/dalvikvm(334): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
01-31 06:43:14.837: E/AndroidRuntime(334): FATAL EXCEPTION: main
01-31 06:43:14.837: E/AndroidRuntime(334): java.lang.RuntimeException: Unable to start activity ComponentInfo{blog.liucc/blog.liucc.MyCommActivity}: java.lang.IllegalArgumentException: column 'number' does not exist
01-31 06:43:14.837: E/AndroidRuntime(334):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
01-31 06:43:14.837: E/AndroidRuntime(334):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
01-31 06:43:14.837: E/AndroidRuntime(334):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
01-31 06:43:14.837: E/AndroidRuntime(334):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
01-31 06:43:14.837: E/AndroidRuntime(334):  at android.os.Handler.dispatchMessage(Handler.java:99)
01-31 06:43:14.837: E/AndroidRuntime(334):  at android.os.Looper.loop(Looper.java:123)
01-31 06:43:14.837: E/AndroidRuntime(334):  at android.app.ActivityThread.main(ActivityThread.java:4627)
01-31 06:43:14.837: E/AndroidRuntime(334):  at java.lang.reflect.Method.invokeNative(Native Method)
01-31 06:43:14.837: E/AndroidRuntime(334):  at java.lang.reflect.Method.invoke(Method.java:521)
01-31 06:43:14.837: E/AndroidRuntime(334):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-31 06:43:14.837: E/AndroidRuntime(334):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-31 06:43:14.837: E/AndroidRuntime(334):  at dalvik.system.NativeStart.main(Native Method)
01-31 06:43:14.837: E/AndroidRuntime(334): Caused by: java.lang.IllegalArgumentException: column 'number' does not exist
01-31 06:43:14.837: E/AndroidRuntime(334):  at android.database.AbstractCursor.getColumnIndexOrThrow(AbstractCursor.java:314)
01-31 06:43:14.837: E/AndroidRuntime(334):  at android.database.CursorWrapper.getColumnIndexOrThrow(CursorWrapper.java:99)
01-31 06:43:14.837: E/AndroidRuntime(334):  at android.widget.SimpleCursorAdapter.findColumns(SimpleCursorAdapter.java:312)
01-31 06:43:14.837: E/AndroidRuntime(334):  at android.widget.SimpleCursorAdapter.<init>(SimpleCursorAdapter.java:87)
01-31 06:43:14.837: E/AndroidRuntime(334):  at blog.liucc.MyCommActivity.onCreate(MyCommActivity.java:42)
01-31 06:43:14.837: E/AndroidRuntime(334):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-31 06:43:14.837: E/AndroidRuntime(334):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
01-31 06:43:14.837: E/AndroidRuntime(334):  ... 11 more
个人觉得问题就在这一句
ListAdapter ccAdapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_2, ccCursor,
         new String[] {PhoneLookup.DISPLAY_NAME, PhoneLookup.NUMBER}, 
         new int[] {android.R.id.text1, android.R.id.text2});但不知道应该如何改。另外,关于Android数据使用,Cursor使用,大家有没有比较好的资料推荐??谢谢!!

解决方案 »

  1.   

    ArrayList<Map<String, Object>> listData = new ArrayList<Map<String, Object>>();
    //cur就是ccCursor 
    while (cur.moveToNext()) {
    Map<String, Object> mp = new HashMap<String, Object>();
     
    long id = cur.getLong(cur.getColumnIndex("_id"));
    Cursor pcur = getContentResolver().query(
    ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
    null,
    ContactsContract.CommonDataKinds.Phone.CONTACT_ID + "="
    + Long.toString(id), null, null);
     
    // 处理多个号码的情况
    String phoneNumbers = "";
    while (pcur.moveToNext()) {
    String strPhoneNumber = pcur
    .getString(pcur
    .getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
    if(phoneNumbers==null||phoneNumbers.trim().length()==0){
    phoneNumbers += strPhoneNumber;
    }else{
    phoneNumbers += strPhoneNumber + ":";
    }
    }
    pcur.close();
     
    String name = cur.getString(cur.getColumnIndex("display_name"));
    mp.put(NAME, name);
    mp.put(NUMBER, phoneNumbers);
    listData.add(mp);
    }
    cur.close();
      

  2.   

    查询的数据中不存在number这一项。log
      

  3.   

    .IllegalArgumentException: column 'number' does not exist
    查询的数据中不存在number这一项 或者说你 ‘number’写错了, 空格或者引号使用不当错误,都会找不到字段
      

  4.   

    将ContactsContract.Contacts.CONTENT_URI改为People.CONTENT_URI这里我打印了所有的列信息,没有number
    for (int j = 0; j < ccCursor.getColumnCount(); j++) {
    String fname = ccCursor.getColumnName(j);
    logger.d(fname);
    }
      

  5.   

    看报错的信息是没有叫做“number”这一个字段 楼上很多人都说了解决方法了,我要说的是那本书我也买过了
    有些写法比较老了。而且在opengl那一章 那个写法就是错误的程序跑不起来;