[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

out of bounds exception when trying Bufferedwriter

Posted on 2012-09-04
3
Medium Priority
?
595 Views
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(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
0
Comment
Question by:willie108
  • 2
3 Comments
 
LVL 36

Expert Comment

by:mccarl
ID: 38366368
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
 

Author Comment

by:willie108
ID: 38366426
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
 
LVL 36

Accepted Solution

by:
mccarl earned 2000 total points
ID: 38366482
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses
Course of the Month19 days, 13 hours left to enroll

873 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