out of bounds exception when trying Bufferedwriter

Hi. I am getting this error when trying to use a Bufferedwriter.

Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 2, Size: 2
        at java.util.ArrayList.rangeCheck(ArrayList.java:604)
        at java.util.ArrayList.get(ArrayList.java:382)
        at weka.core.Attribute.value(Attribute.java:796)
        at weka.core.AbstractInstance.stringValue(AbstractInstance.java:620)
        at weka.core.AbstractInstance.stringValue(AbstractInstance.java:599)
        at weka.core.AbstractInstance.toString(AbstractInstance.java:674)
        at weka.core.DenseInstance.toStringNoWeight(DenseInstance.java:293)
        at weka.core.AbstractInstance.toString(AbstractInstance.java:640)
        at java.lang.String.valueOf(String.java:2902)
        at java.lang.StringBuffer.append(StringBuffer.java:232)
        at weka.core.Instances.stringWithoutHeader(Instances.java:1413)
        at weka.core.Instances.toString(Instances.java:1397)
        at CSVInputMC3.main(CSVInputMC3.java:116)

Any suggestions on how to fix this?
Thanks!
CSVInputMC3.java
willie108Asked:
Who is Participating?
 
mccarlConnect With a Mentor IT Business Systems Analyst / Software DeveloperCommented:
Ok, I probably don't know enough about the Weka stuff to help then.

What I see is happening is that while it may be something to do with your data that is causing this, the error that is occurring is due to the Weka library developer NOT coding defnesively enough. This type of error should be something that the library traps as it is in a better position to translate that into a more user friendly error message (if it is indeed due to the input data) or just handle it itself.

But some things to try would be to make sure that you are using the latest version, submit a Bug Report (instructions on their homepage, http://www.cs.waikato.ac.nz/ml/weka/) or download the source code (if not done already) and have a look to see if you can fix their code yourself.
0
 
mccarlIT Business Systems Analyst / Software DeveloperCommented:
The error may be happening on the line where you are using the BufferedWriter but it has nothing to do with BufferedWriter. If you look at the stack trace (second last line) the error is actually starts with the Instances.toString() method which in your code is the "labeled.toString()" call that is then passed to the BufferedWriter.write() method.

So, this error is due to code in the Weka libraries but I don't have experience using Weka. I noticed that you had another fairly similar out of bounds issue that you asked about here a couple of days ago. I see that you have resolved that issue, but you didn't indicate how you resolved it. But maybe the two issues are linked in some way. If that hasn't helped you to resolve this one, can you post what you did to fix the previous issue and we may be able to help then for this one.
0
 
willie108Author Commented:
Hi. Thanks. The code is supposed to take two data sets as input and then output another data set. If the key variable in the two data sets vary in the set of possible values that are in those respective columns then this error is occurring. I 'fixed' it last time by adding in values that occurred in one to the other. But the 'inputmappedClassifier' stuff in the code is supposed to alleviate this problem. But it is still occurring.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.