-1

I'm writing a MTL file loader for my game engine. I am using a Scanner attached to a FileInputStream to read from the file. When trying to read the line

Ks 0.500000 0.500000 0.500000

A InputMismatchException is thrown (by Scanner), the stacktrace leading to my code:

protected ColorRGBA readColor() {
    ColorRGBA color = new ColorRGBA();
    color.set(scanner.nextFloat(), scanner.nextFloat(), scanner.nextFloat(), scanner.nextFloat());

    return color;
}

It works on the previous statements using the same method. I'm not sure why the exception is being thrown by this line, but not the others, all in the same format (but different commands and numbers, obviously). Why is this exception being thrown?

Isaac Woods
  • 1,114
  • 1
  • 17
  • 28

1 Answers1

0

As already stated in the comments of your question, you provide one string and 3 floats as input, but you are trying to load/read 4 floats which of course throws an InputMismatchException. I don't know your other input lines but if they also contain strings, they can't really work. Check the inputs again or correct your read method.

Niklas S.
  • 1,046
  • 10
  • 22
  • Aha, thank you. I couldn't find what a InputMismatchException was thrown for in the Javadoc, kinda confused me. The lines read successfully follow the same format, the first being 'Ka 0.000000 0.000000 0.000000'. This is parsed successfully, why would this be? By specification, the line should include an alpha value, which is why I'm reading a forth float, guess it wasn't included in a Blender generated file. Thanks again. – Isaac Woods Aug 02 '14 at 19:19