【发布时间】:2016-01-02 21:12:42
【问题描述】:
我正在加载包含所有联系人组的ListView。以下是我为此编写的代码:
来自GroupActivity.java的代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_group);
Cursor groupCursor = getContentResolver().query(
ContactsContract.Data.CONTENT_URI,
new String[]{ContactsContract.Groups._ID,
ContactsContract.Groups.TITLE}, null, null, null
);
ListView groupListView = (ListView) findViewById(R.id.contactList);
groupListView.setAdapter(new SimpleCursorAdapter(
this, R.id.contactList, groupCursor, new String[]{
ContactsContract.Groups.TITLE
}, new int[] {R.id.list_item}, 0
));
groupListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Toast.makeText(me, "Notification will be sent soon" , Toast.LENGTH_SHORT);
}
});
}
这是我的看法:
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/contactList"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
很简单。但是当我运行应用程序时,我得到一个异常,原因如下:
Caused by: java.lang.IllegalArgumentException: Invalid column title
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:167)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:137)
at android.content.ContentProviderProxy.query(ContentProviderNative.java:413)
at android.content.ContentResolver.query(ContentResolver.java:462)
at android.content.ContentResolver.query(ContentResolver.java:405)
at com.tariq.mysms.GroupActivity.onCreate(GroupActivity.java:26)
at android.app.Activity.performCreate(Activity.java:5264)
我想知道为什么它将title 称为无效列,尽管我也清楚地查询了该列。那是因为我在to 参数中使用的视图类型吗?非常感谢任何帮助。
【问题讨论】:
标签: android listview simplecursoradapter