In the code below the for loop is giving an "java.lang.ArrayIndexOutOfBoundsException: 2" error, i can not see why, if i change "emailArray[i][2] = messageContent[i]" to "emailArray[i][1] = messageContent[i]" it works, is my layout for the 2d array wrong?
public String[][] fetchEmails() throws Exception {
String[][] emailArray;
Properties props = new Properties();
Session session = Session.getDefaultInstance(props, null);
Store store = session.getStore("imaps");
store.connect("pop.gmail.com", "******@googlemail.com", "********");
System.out.println(store);
Folder folder = store.getFolder("Inbox");
folder.open(Folder.READ_ONLY);
int howmuch = folder.getMessageCount();
Message message[] = folder.getMessages();
String[] messageContent = new String[message.length];
messageContent = convertContent(message);
emailArray = new String[message.length][2];
for (int i = 0; i<message.length; i++){
emailArray[i][0] = message[i].getFrom()[0].toString();
emailArray[i][1] = message[i].getSubject().toString();
emailArray[i][2] = messageContent[i];
}
folder.close(false);
store.close();
return emailArray;
}