【发布时间】:2009-10-25 07:11:58
【问题描述】:
我刚刚开始使用 Android SDK,但我的第一个应用程序出现问题。目前,我正在尝试在一个大列表中列出所有用户。但是,无论我尝试什么,该应用程序都会继续强制关闭。我在示例文件中找到了代码,但这仍然给我带来了问题。下面是我正在使用的代码。
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String[] projection = new String[] {
People._ID,
People._COUNT,
People.NAME,
People.NUMBER
};
//Get the base URI for the People table in the Contacts content provider.
Uri contacts = People.CONTENT_URI;
//Make the query.
Cursor managedCursor = managedQuery(contacts,
projection, // Which columns to return
null, // Which rows to return (all rows)
null, // Selection arguments (none)
// Put the results in ascending order by name
People.NAME + " ASC");
Cursor c = getContentResolver().query(Contacts.CONTENT_URI, null, null, null, null);
startManagingCursor(c);
String[] columns = new String[] {People.NAME};
int[] names = new int[] {R.id.text1};
SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(this,
R.layout.main, c, columns, names);
setListAdapter(mAdapter);
}
这是直接来自示例文件,但仍然出错。我发现导致问题的行是“Cursor managedCursor = managedQuery(contacts”行。有其他人看到这个吗?我很茫然,经过 2 小时或研究后没有找到任何解决方案。
另外,我在我的应用清单文件中添加了以下行:
<uses-permission android:name="android.permission.READ_CONTACTS"></uses-permission>
谢谢,如果您需要更多信息,请告诉我。
【问题讨论】:
标签: android