开发者

Google calendar indexoutofbounds when getTimes()

开发者 https://www.devze.com 2023-01-06 16:18 出处:网络
I\'m trying to write a simple method, that gets events from Google calendar. The problem is that if i\'m trying to call getTimes() on my events, i get an Indexoutofbounds exception.

I'm trying to write a simple method, that gets events from Google calendar. The problem is that if i'm trying to call getTimes() on my events, i get an Indexoutofbounds exception. I just can't figure out what the problem is.

Thanks in advance :)

    jTextArea1.setText("");

    try {
        CalendarService myService = new CalendarService("myApp");
        myService.setUserCredentials(username, password);
        String eventTitle = "";

        for (URL u : urls) {

            CalendarQuery myQuery = new CalendarQuery(u);

            myQuery.setMinimumStartTime(convertStartDateToDateTime());
            myQuery.setMaximumStartTime(convertEndDateToDateTime());
            myQuery.setFullTextQuery(searchTF.getText());

            CalendarEventFeed resultFeed = myService.query(myQuery, CalendarEventFeed.class);
            //  System.out.println(resultFeed.getTitle().getPlainText());

            for (int i = 0; i < resultFeed.getEntries().size(); i++) {开发者_如何学Python
                CalendarEventEntry entry = resultFeed.getEntries().get(i);

                if (resultFeed.getEntries().size() > 0) {
                    jTextArea1.setText(jTextArea1.getText()
                            + resultFeed.getTitle().getPlainText()
                            + "\n");

                    eventTitle = resultFeed.getEntries().get(i).getTitle().getPlainText();
                    jTextArea1.setText(jTextArea1.getText() + eventTitle + "\n");

                    jTextArea1.setText(jTextArea1.getText()
                            + "Start: " + resultFeed.getEntries().get(i).getTimes().get(i).getStartTime().toString() + "\n"
                            + "Slut: " + resultFeed.getEntries().get(i).getTimes().get(i).getEndTime().toString() + "\n");
                }
                jTextArea1.setText(jTextArea1.getText() + "\n");
            }
        }


My guess is something is wrong with your second get(i),

resultFeed.getEntries().get(i).getTimes().get(i).getStartTime().toString()

While the first "i" in the get(i) is guaranteed to work because of i < resultFeed.getEntries().size(); condition in the for loop, the second "i" in the get(i) doesn't have any condition to check its range.

Kindly Post your full exception trace if this isn't your problem.

0

精彩评论

暂无评论...
验证码 换一张
取 消