Reputation: 678
The following code throws IndexOutOfBoundsException. Any idea why?
Folder folder = store.getDefaultFolder();
folder = folder.getFolder("INBOX");
int totalMessages = folder.getMessageCount();
//totalMessages is 17000
folder.getMessages(16900, 16999) --- here I am trying to get the NEWEST 99 messages.
This code throws the exception indexoutofbounds even though there are so many mails. What am I doing wrong?
Upvotes: 4
Views: 2139
Reputation: 1001
please open the folder in read or read_write mode first.
folder.open(Folder.READ_WRITE);
Upvotes: 0
Reputation: 4707
Never us magic values in code, it will just cause you pain. Try:
int messagesToDisplay = 100;
folder.getMessages(totalMessages - messagesToDisplay , totalMessages);
From the JavaDoc the messages are identified with a 1 based array not 0.
Can you also add the stack trace please.
Upvotes: 5