title: InvocationTargetException while trying to add variables to a new object
body: <p>I am trying to send two variables from one sketch to another, using the oscP5 library for processing.
  The message I am sending is created like this:</p>
  
  <pre><code> OscMessage myMessage = new OscMessage("/test");
   myMessage.add(title);
   myMessage.add("Zeit");
   oscP5.send(myMessage, remoteLocation);
  </code></pre>
  
  <p>In the second sketch, I receive the data like that:</p>
  
  <pre><code> void oscEvent(OscMessage theOscMessage) {
     if(theOscMessage.checkAddrPattern("/test")) {
       String title = theOscMessage.get(0).stringValue();
       String layoutType = theOscMessage.get(1).stringValue();
  
       addToQueue(title, layoutType);
     }
   }
  </code></pre>
  
  <p>And here my simplified addToQueue function:</p>
  
  <pre><code> void addToQueue(String title, String layoutType) {
     if(!existsInQueues(title)) {
       upcomingHeadlines.add(new Headline(title, printAxis, scrollSpeed, layoutType));
     } 
   }
  </code></pre>
  
  <p>Every time I start the sketches, I get the error:</p>
  
  <blockquote>
    <p>ERROR @ OscP5 ERROR. an error occured while forwarding an OscMessage to a method in your program. please check your code for any possible errors that might occur in the method where incoming OscMessages are parsed e.g. check for casting errors, possible nullpointers, array overflows ... .
    method in charge : oscEvent  java.lang.reflect.InvocationTargetException</p>
  </blockquote>
  
  <p>I have been able to track the problem down to the <code>layoutType</code>-Variable. If I change</p>
  
  <pre><code>  String layoutType = theOscMessage.get(1).stringValue();
  </code></pre>
  
  <p>to</p>
  
  <pre><code>  String layoutType = "Zeit";
  </code></pre>
  
  <p>no error occurs.
  That is quite confusing, because both versions should have the same result.
  The error message does not help me in any way.</p>
  
  <hr>
  
  <h2>Edit</h2>
  
  <p>I have compared the two possible variables like that:</p>
  
  <pre><code>String layoutType = theOscMessage.get(1).stringValue();
  String layoutTypeB = "Zeit";
  if(layoutType.equals(layoutTypeB)) println("Same String!");
  </code></pre>
  
  <p>Since gets printed to the console, both have to be the same … I really do not know where to search for an error anymore.</p>
  
  <hr>
  
  <h2>Edit 2</h2>
  
  <p>I have wrapped my second sketch in <code>try {...} catch(Exception ex) {ex.printStackTrace();}</code> like that:</p>
  
  <pre><code>void oscEvent(OscMessage theOscMessage) {
    try {  
      if(theOscMessage.checkAddrPattern("/test")) {
        if(debug &amp;&amp; debugFeed) println("Received message from other sketch.");
  
        String title = theOscMessage.get(0).stringValue();
        String layoutTypeO = (String)theOscMessage.get(1).stringValue();
        String layoutType = "Zeit";
        if(debug &amp;&amp; debugTemp) {
          if(layoutType.equals(layoutTypeO)) println("IS DOCH GLEICH!");
        }
        if(debug &amp;&amp; debugFeed) println("Parsed Information.");
        if(debug &amp;&amp; debugFeed) println("-----");
        addToQueue(title, layoutTypeO);
      }
    } catch(Exception ex) {ex.printStackTrace();}
  }
  </code></pre>
  
  <p>That gives me this error as result:</p>
  
  <pre class="lang-none prettyprint-override"><code>java.lang.IndexOutOfBoundsException: Index: 0, Size: 0  
      at java.util.ArrayList.rangeCheck(ArrayList.java:635)  
      at java.util.ArrayList.get(ArrayList.java:411)  
      at printer$Headline.useLayout(printer.java:260)  
      at printer$Headline.&lt;init&gt;(printer.java:188)  
      at printer.addToQueue(printer.java:407)  
      at printer.oscEvent(printer.java:395)  
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)  
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)  
      at java.lang.reflect.Method.invoke(Method.java:606)  
      at oscP5.OscP5.invoke(Unknown Source)  
      at oscP5.OscP5.callMethod(Unknown Source)  
      at oscP5.OscP5.process(Unknown Source)  
      at oscP5.OscNetManager.process(Unknown Source)  
      at netP5.AbstractUdpServer.run(Unknown Source)  
      at java.lang.Thread.run(Thread.java:744)
  </code></pre>
  
  <hr>
  
  <h2>Edit 4</h2>
  
  <p>Constructor for my <code>Headline</code>-Class:</p>
  
  <pre><code>class Headline {
  
    //Define Variables
    Layout layout;
    String title, lastHeadline;
    float yPos, speed;
    float transparency = 255;
    boolean fullyPrinted = false;
    int boundingBoxHeight;
  
    // Initialize Class Function
    Headline(String t, float y, float s, String lay) {
      title = t;
      yPos = y;
      speed = s;
      layout = useLayout(lay);
      boundingBoxHeight = calculateTextHeight(title);
    }
  </code></pre>
  
  <p>You might want to know about <code>useLayout()</code> too, so here it is:</p>
  
  <pre><code>Layout useLayout(String name) {
      ArrayList layoutVariants = new ArrayList&lt;Layout&gt;();
      int existingLayouts = layouts.size();
      Layout chosenLayout;
  
      for(int i = 0; i &lt; existingLayouts; i++) {
        Layout currentLayout = (Layout)layouts.get(i);
        if(currentLayout.layoutType == name) {
          layoutVariants.add(currentLayout);
        }
      }
  
      if(layoutVariants != null) {
        int rand = (int)(Math.random() * layoutVariants.size());
        chosenLayout = (Layout)layoutVariants.get(rand);
      } else {
        chosenLayout = (Layout)layouts.get((int)(Math.random() * existingLayouts)); 
      }
    return chosenLayout;
  }
  </code></pre>