controlp5 multilist.add() arrayindexoutofbounds 8217

edited February 2014 in Library Questions

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:

    ControlP5 2.0.4 infos, comments, questions at http://www.sojamo.de/libraries/controlP5
    [0] "testFileENC.txt"
    [1] "testFileENCList.txt"
    [2] "testFileENCList2.txt"
    
    testFileENC
    5
    0: 1: you’re getting there, 111
    1: 1: way to go, 112
    2: 1: finish strong, 113
    3: 1: just a few seconds more, 114
    4: 1: that’s it, 115
    
    testFileENCList
    8
    0: 2: you’re getting there, 121
    1: 2: way to go, 122
    2: 2: finish strong, 123
    3: 2: just a few seconds more, 124
    4: 2: that’s it, 125
    5: 2: there you go, 126
    6: 2: almost there, 127
    7: 2: keep trying, 128
    
    testFileENCList2
    10
    0: 3: you’re getting there, 131
    1: 3: way to go, 132
    2: 3: finish strong, 133
    3: 3: just a few seconds more, 134
    4: 3: that’s it, 135
    5: 3: there you go, 136
    6: 3: almost there, 137
    7: 3: keep trying, 138
    8: 3: a little louder, 139
    9: 3: just passed the target, 140
    
    java.lang.RuntimeException: java.lang.ArrayIndexOutOfBoundsException: 8217
        at com.jogamp.common.util.awt.AWTEDTExecutor.invoke(AWTEDTExecutor.java:58)
        at jogamp.opengl.awt.AWTThreadingPlugin.invokeOnOpenGLThread(AWTThreadingPlugin.java:100)
        at jogamp.opengl.ThreadingImpl.invokeOnOpenGLThread(ThreadingImpl.java:205)
        at javax.media.opengl.Threading.invokeOnOpenGLThread(Threading.java:172)
        at javax.media.opengl.Threading.invoke(Threading.java:191)
        at javax.media.opengl.awt.GLCanvas.display(GLCanvas.java:483)
        at processing.opengl.PGL.requestDraw(PGL.java:1149)
        at processing.opengl.PGraphicsOpenGL.requestDraw(PGraphicsOpenGL.java:1604)
        at processing.core.PApplet.run(PApplet.java:2176)
        at java.lang.Thread.run(Thread.java:695)
    Caused by: java.lang.ArrayIndexOutOfBoundsException: 8217
        at controlP5.BitFont.getGlyph(Unknown Source)
        at processing.opengl.PGraphicsOpenGL.textCharImpl(PGraphicsOpenGL.java:3347)
        at processing.core.PGraphics.textLineImpl(PGraphics.java:4666)
        at processing.opengl.PGraphicsOpenGL.textLineImpl(PGraphicsOpenGL.java:3321)
        at processing.core.PGraphics.textLineAlignImpl(PGraphics.java:4656)
        at processing.core.PGraphics.text(PGraphics.java:4353)
        at processing.core.PGraphics.text(PGraphics.java:4304)
        at processing.core.PApplet.text(PApplet.java:12902)
        at controlP5.ControlFont.draw(Unknown Source)
        at controlP5.Label.draw(Unknown Source)
        at controlP5.Label$SinglelineLabel.draw(Unknown Source)
        at controlP5.Label.draw(Unknown Source)
        at controlP5.Button$ButtonView.display(Unknown Source)
        at controlP5.Button$ButtonView.display(Unknown Source)
        at controlP5.Controller.draw(Unknown Source)
        at controlP5.ControllerGroup.drawControllers(Unknown Source)
        at controlP5.ControllerGroup.draw(Unknown Source)
        at controlP5.ControlWindow.draw(Unknown Source)
        at sun.reflect.GeneratedMethodAccessor6.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at processing.core.PApplet$RegisteredMethods.handle(PApplet.java:1159)
        at processing.core.PApplet$RegisteredMethods.handle(PApplet.java:1152)
        at processing.core.PApplet.handleMethods(PApplet.java:1346)
        at processing.core.PApplet.handleDraw(PApplet.java:2320)
        at processing.opengl.PGL$PGLListener.display(PGL.java:2601)
        at jogamp.opengl.GLDrawableHelper.displayImpl(GLDrawableHelper.java:588)
        at jogamp.opengl.GLDrawableHelper.display(GLDrawableHelper.java:572)
        at javax.media.opengl.awt.GLCanvas$7.run(GLCanvas.java:1054)
        at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1034)
        at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:909)
        at javax.media.opengl.awt.GLCanvas$8.run(GLCanvas.java:1065)
        at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:199)
        at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:715)
        at java.awt.EventQueue.access$400(EventQueue.java:82)
        at java.awt.EventQueue$2.run(EventQueue.java:676)
        at java.awt.EventQueue$2.run(EventQueue.java:674)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:86)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:685)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
    
Sign In or Register to comment.