Cursor.moveToFirst()和Cursor.moveToNext()返回NULL

时间:2013-03-18 06:13:03

标签: android

我正在尝试制作谷歌日历服务。

这是我关于日历的代码。

if(android.os.Build.VERSION.SDK_INT >= 14)
    {
        LogShow("14");
        final String[] COLS = new String[] {
                CalendarContract.Events.TITLE, 
                CalendarContract.Events.DTSTART, 
                CalendarContract.Events.DTEND, 
                CalendarContract.Events.EVENT_LOCATION
        };

        String TtsData = "";
        Cursor mCursor = mContext.getContentResolver().query(
                CalendarContract.Events.CONTENT_URI, COLS, null, null, null);

        if(mCursor.moveToFirst())
        {
            LogShow("mCursor.moveToFirst()==NULL");
        }
        Calendar c = Calendar.getInstance();
        int day = c.get(Calendar.DAY_OF_MONTH);
        int month = c.get(Calendar.MONTH);
        int year = c.get(Calendar.YEAR);
        int hour = c.get(Calendar.HOUR_OF_DAY);
        while(mCursor.moveToNext())
        {
            LogShow("mCursor.moveToNext()");
            String title = mCursor.getString(0);
            Date begin = new Date(mCursor.getLong(1));
            Date end = new Date(mCursor.getLong(2));
            String EventLocation = mCursor.getString(3);
            if(begin.getDate() == day && begin.getMonth() == month && begin.getYear()+1900 == year)
            {
                LogShow("begin.getDate() == day && begin.getMonth() == month && begin.getYear()+1900 == year");
                if(hour < begin.getHours())
                {
                    if(!EventLocation.equals(""))
                    {
                        if(Value.location.equals(Value.EnglishUK) || Value.location.equals(Value.EnglishUS) ||  Value.location.equals(Value.Canada))
                        {
                            TtsData += " , " + "Title is " + title + ", " + "Start Time" + " , " + 
                            begin.getHours() + ", End Time , " + end.getHours() + ", Event Location , " 
                            + EventLocation + " , ";
                        }
                        else if(Value.location.equals(Value.French) || Value.location.equals(Value.CanadaFrench))
                        {
                            TtsData += " , " + "Intitulé " + title + ", " + "Début" + " , " + 
                            begin.getHours() + ", Fin , " + end.getHours() + ", Lieu de rendez-vous , " 
                            + EventLocation + " , ";                            
                        }
                        else if(Value.location.equals(Value.Germany))
                        {
                            TtsData += " , " + "Titel ist " + title + ", " + "Startzeit" + " , " + 
                            begin.getHours() + ", Endzeit , " + end.getHours() + ", Veranstaltungsort , " 
                            + EventLocation + " , ";                            
                        }
                        else if(Value.location.equals(Value.Italian))
                        {
                            TtsData += " , " + "Titolo è " + title + ", " + "Ora d'inizio" + " , " + 
                            begin.getHours() + ", Ora fine , " + end.getHours() + ", Luogo dell'evento , " 
                            + EventLocation + " , ";                            
                        }
                    }
                    else
                    {
                        if(Value.location.equals(Value.EnglishUK) || Value.location.equals(Value.EnglishUS) || 
                                Value.location.equals(Value.Canada))
                        {
                            TtsData += " , " + "Title is " + title + ", " + "Start Time" + " , " + 
                            begin.getHours() + ", End Time , " + end.getHours();
                        }
                        else if(Value.location.equals(Value.French) || Value.location.equals(Value.CanadaFrench))
                        {
                            TtsData += " , " + "Intitulé " + title + ", " + "Début" + " , " + 
                            begin.getHours() + ", Fin  , " + end.getHours();
                        }
                        else if(Value.location.equals(Value.Germany))
                        {
                            TtsData += " , " + "Titel ist " + title + ", " + "Startzeit" + " , " + 
                            begin.getHours() + ", Endzeit , " + end.getHours();                         
                        }
                        else if(Value.location.equals(Value.Italian))
                        {
                            TtsData += " , " + "Titolo è " + title + ", " + "Ora d'inizio" + " , " + 
                            begin.getHours() + ", Ora fine , " + end.getHours();                            
                        }
                    }
                }
            }
        }

        if(TtsData.equals(""))
        {
            Value.TTS_Data = "You don't have schedule";
            new TextToVoice(mContext, TextToVoice.SPEECH);
        }
        else
        {
            Value.TTS_Data = TtsData;
            new TextToVoice(mContext, TextToVoice.SPEECH);
        }
    }   
}

版本API14 up,Cursor.moveToFirst和Cursor.moveToNext将返回NULL,尽管日历事件已经存在。

如何解决此问题?

0 个答案:

没有答案
相关问题