title: WEKA - java.lang.IndexOutOfBoundsException error when using the api
body: <p>I have used <code>FilteredClassifier</code> to create a model. Now I want to evaluate the model on a test set. 
  I can do this through the GUI, but when using the API, my java program creates an error when it tries to call <code>classifyInstance()</code> method. </p>
  
  <p>Below are the test file, java program and error message I receive</p>
  
  <h2>Test file:</h2>
  
  <blockquote>
    <p>@relation train-weka.filters.unsupervised.attribute.Remove-R2-weka.filters.unsupervised.attribute.NominalToString-C1 </p>
    
    <p>@attribute QUOTE string 
    @attribute CAT {Art,Beauty,Love,Life,Knowledge,Truth,Best,Strength,Great,Friendship,Hope,Power,Funny} </p>
    
    <p>@data 
    'True art is characterized by an irresistible urge in the creative artist.',? </p>
  </blockquote>
  
  <h2>Java code:</h2>
  
  <pre><code>public class test { 
  
          public static void main(String[] args) throws FileNotFoundException, Exception { 
                  // TODO Auto-generated method stub 
  
                  String fileName = "./tree.model"; 
                  ObjectInputStream in = new ObjectInputStream(new FileInputStream(fileName)); 
                  Object tmp = in.readObject(); 
                  FilteredClassifier tree = (FilteredClassifier) tmp; 
                  in.close(); 
                  System.out.println("===== Loaded model: " + fileName + " ====="); 
  
  
                  // load unlabeled data 
                  Instances unlabeled = new Instances(new BufferedReader(new FileReader("./test3.arff"))); 
  
  
                   System.out.println(unlabeled); 
  
                   // set class attribute 
                   unlabeled.setClassIndex(unlabeled.numAttributes() - 1); 
  
                   // create copy 
                   Instances labeled = new Instances(unlabeled); 
  
                   // label instances 
                   for (int i = 0; i &lt; unlabeled.numInstances(); i++) { 
                     double clsLabel = tree.classifyInstance(unlabeled.instance(i)); 
                     labeled.instance(i).setClassValue(clsLabel); 
                   } 
                   // save labeled data 
                   BufferedWriter writer = new BufferedWriter(new FileWriter("/some/where/labeled.arff")); 
                   writer.write(labeled.toString()); 
                   writer.newLine(); 
                   writer.flush(); 
                   writer.close(); 
          } 
  } 
  </code></pre>
  
  <h2>Error stack:</h2>
  
  <pre><code>Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 
          at java.util.ArrayList.rangeCheck(Unknown Source) 
          at java.util.ArrayList.get(Unknown Source) 
          at weka.core.Instances.attribute(Instances.java:341) 
          at weka.core.AttributeLocator.locate(AttributeLocator.java:153) 
          at weka.core.AttributeLocator.initialize(AttributeLocator.java:119) 
          at weka.core.AttributeLocator.&lt;init&gt;(AttributeLocator.java:102) 
          at weka.core.StringLocator.&lt;init&gt;(StringLocator.java:69) 
          at weka.filters.Filter.flushInput(Filter.java:431) 
          at weka.filters.unsupervised.attribute.StringToWordVector.batchFinished(StringToWordVector.java:768) 
          at weka.classifiers.meta.FilteredClassifier.filterInstance(FilteredClassifier.java:474) 
          at weka.classifiers.meta.FilteredClassifier.distributionForInstance(FilteredClassifier.java:495) 
          at weka.classifiers.AbstractClassifier.classifyInstance(AbstractClassifier.java:70) 
          at test.main(test.java:43)
  </code></pre>