Search code examples
javanumberformatexception

Error: Input number format exception


I am trying to use the source code from the cluster-algorithms-java-alpha library this is the link

https://code.google.com/p/cluster-algorithms-java-alpha/source/browse/tags/rewritepending/src/tests/validationIndices/SilhouetteIndexTest.java?r=6

When I try to run it it runs perfectly.

I have taken the IRIS dataset from the uci repository

I have modified the code

//this.trivialTestset =InputReader.readFromfile("C:\\Users\\USERNAME\\Desktop\\Coding\\Clusterer\\src\\easy.valid");

    this.trivialTestset =InputReader.readFromfile("C:\\Users\\USERNAME\\Desktop\\Coding\\Clusterer\\src\\iris.txt");

I m getting these errors

java.lang.NumberFormatException: For input string: "5.1,3.5,1.4,0.2,Iris-setosa"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at input.FeatureVector.<init>(FeatureVector.java:17)
at input.InputReader.readFromfile(InputReader.java:34)
at input.InputReader.readFromfile(InputReader.java:61)
at tests.validationIndices.SilhouetteIndexTest.setup(SilhouetteIndexTest.java:27)

Solution

  • The dataset is not formatted properly.

    The easy.valid file is properly formatted, make sure the iris.txt file is formatted the exact same.

    If it's not, you're gonna have to write your own input parser.