out of bounds exception when trying Bufferedwriter

Posted on 2012-09-04
Last Modified: 2012-09-05
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(
        at java.util.ArrayList.get(
        at weka.core.Attribute.value(
        at weka.core.AbstractInstance.stringValue(
        at weka.core.AbstractInstance.stringValue(
        at weka.core.AbstractInstance.toString(
        at weka.core.DenseInstance.toStringNoWeight(
        at weka.core.AbstractInstance.toString(
        at java.lang.String.valueOf(
        at java.lang.StringBuffer.append(
        at weka.core.Instances.stringWithoutHeader(
        at weka.core.Instances.toString(
        at CSVInputMC3.main(

Any suggestions on how to fix this?
Question by:willie108
    LVL 35

    Expert Comment

    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.

    Author Comment

    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.
    LVL 35

    Accepted Solution

    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, or download the source code (if not done already) and have a look to see if you can fix their code yourself.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
    Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
    Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
    This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now