We are about to switch to a new forum software. Until then we have removed the registration on this forum.
hello,
i have been struggling (going on 12hrs, unfortunately) with adding a second level of items to a multilist. the code works well until i try to add the 3rd level list. to start the multilist, i have a node that connects to a list of 3 items that are read from a folder. the names of the files in the folder are used to label the nodes in the second level. for the 3rd level, i have lined read from each file and would like to add the number of items equal to the number of lines in the read file. when i execute this .add(), i receive and an out of bounds error 8217. i have enclosed the code below with comments:
MultiList encourageMessagesList; // initialized before setup
...
savedEncourageMessagesFolder = new File(sketchPath("savedMessageFiles/encouragementMessages")); // in setup()
...
//in event listener
if(theControlEvent.isFrom("loadEncourageMessageFile"))
{
loadEncourageMessagesMultiList();
}
...
//my function
void loadEncourageMessagesMultiList()
{
encourageMessagesList = cp5.addMultiList("loadEncourageMessageListFiles", row2, 385, 100, 20); // position, size
MultiListButton encourageMessagesFilesRoot = encourageMessagesList.add("encourage files", 1); //works fine
char encourageMessagesFilesListExtensionSeparator = '.';
savedEncourageMessagesFilenames = savedEncourageMessagesFolder.list();
savedEncourageMessagesFilenames = subset(savedEncourageMessagesFilenames, 1, 3);
// i had to view hidden files on my computer. even though they are hidden again, the hidden file shows up in my array,
// so i created a subset that ignores it.
println(savedEncourageMessagesFilenames.length); //this length is 3 (0, 1, 2)
println(savedEncourageMessagesFilenames); //works fine
println();
for (int i = 0; i <= savedEncourageMessagesFilenames.length - 1; i++)
{
savedEncourageMessagesFilenames[i] = savedEncourageMessagesFilenames[i].substring(0, savedEncourageMessagesFilenames[i].indexOf(encourageMessagesFilesListExtensionSeparator)); //works fine
MultiListButton encourageMessagesFilesList = encourageMessagesFilesRoot.add(savedEncourageMessagesFilenames[i], 10 + (i + 1)); //works fine
encourageMessageLines = loadStrings("savedMessageFiles/encouragementMessages/" + savedEncourageMessagesFilenames[i] + ".txt"); //reads the lines from the files listed in the previous level
println(savedEncourageMessagesFilenames[i]); //works fine
println(encourageMessageLines.length); //works fine the lengths are: 5, 8, 10, respectively
for(int j = 0; j <= encourageMessageLines.length - 1; j ++)
{
println(j + ": " + (i + 1) + ": " + encourageMessageLines[j] + ", " + str(100 + ((i + 1) * 10) + j + 1)); //works fine
// this next line triggers the array out of bounds 8217 error
// i have tested it many ways for many hours (still doesn't work without indexes i and j)
// and it seems i may have a problem in the add()?
MultiListButton encourageMessageLinesList = encourageMessagesFilesList.add((i + 1) + ": " + encourageMessageLines[j], 100 + ((i + 1) * 10) + j + 1); // had to add the (i + 1) to make unique objects
encourageMessageLinesList.setLabel(encourageMessageLines[j]);
}
println();
}
}
thanks in advance,
destro.
Answers
Hi, can you post the full error message / stack trace?
hi, here's the output of the print statement and the stack trace of the error: