本人最近才开始学习android开发
依照着sdk的doc学习,在dev guide模块的content provider栏目遇到了困难,我参照着它提供的例子敲了一段这样的代码用于输出联系人的信息,但是在输出,也久石do while的循环体里边老是报CursorIndexoutofBoundsException
表示非常的迷茫啊,我完全是按照sdk里边的实例来的阿??
[code=Java]package com.Kiro.Test;
import android.app.Activity;
import android.content.ContentResolver;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Contacts.People;
public class TestActivity extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
setContentView(R.layout.main);
Uri uri=People.CONTENT_URI;
String projection[]=new String[]{People._ID,People.NAME,People.NUMBER};
Cursor cur=this.managedQuery(uri, projection, null, null, null);
int id=cur.getColumnIndex(People._ID);
int count=cur.getColumnIndex(People._COUNT);
int name=cur.getColumnIndex(People.NAME);
int number=cur.getColumnIndex(People.NUMBER);
super.onCreate(savedInstanceState);
do{
System.out.print(cur.getString(id));
System.out.print(cur.getString(count));
System.out.print(cur.getString(name));
System.out.print(cur.getString(number));
System.out.println( " ");
}while(cur.moveToNext());
}
}[/code]
------解决方案--------------------
先把游标移到首位,再取数据。。