我正在使用以下代码获取所有日历并获取每个日历中的第一个事件
但是当我执行查询时它失败了
我正在使用以下URI:
Uri.Builder builder = Uri.parse("content://com.android.calendar/instances/when").buildUpon();
我已经检查过了,我得到了正确的日历ID列表,这里是查询代码:
Cursor eventCursor = null;
// Create an event cursor to find all events in the calendar
try {
eventCursor = contentResolver.query(builder.new String[] { "title", "begin", "end", "allDay"}, "Calendars._id=" + 1, null, "startDay ASC, startMinute ASC");
Log.d(TAG,"Got Calendar ID = "+id);
} catch (Exception e) {
Log.d(TAG, "Didn't find calender for ID="+id);
eventCursor = null;
}
我从SQL中收到以下错误:illegalargumentexception invalid column begin
我搜索了这个错误,什么都没找到,另外,我看到所有这类查询都使用了这些确切的列并获得了成功。
答案 0 :(得分:3)
您在query()方法中给出了错误的参数。以下是一些示例代码:
final ContentResolver resolver = getContentResolver(); final String [] projection = {People._ID,People.NAME,People.NUMBER}; final String sa1 =“%A%”; //包含“A” cursor = resolver.query(People.CONTENT_URI,projection,People.NAME +“LIKE?”, new String [] {sa1},null);
查看此链接以获取更多详细信息: http://developer.android.com/reference/android/content/ContentResolver.html#query%28android.net.Uri,%20java.lang.String[],%20java.lang.String,%20java.lang.String [],%20java.lang.String%29
答案 1 :(得分:1)
您正在开始列中传递 null 。
eventCursor = contentResolver.query(builder.new String[] { "title", "begin", "end", "allDay"}, "Calendars._id=" + 1, null, "startDay ASC, startMinute ASC");