pires / obd-java-api

OBD-II Java API
Apache License 2.0
595 stars 295 forks source link

Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 2, Size: 0 #12

Closed lkrasner closed 10 years ago

lkrasner commented 10 years ago

I think this means the data is not actually being read, since the buffer is empty.

Everything worked perfectly once, then next time I tried, with no cone changes, it stopped.

public static void main(String[] args) throws IOException, InterruptedException {
    SerialPort serialPort = new SerialPort("/dev/rfcomm0");
    try {
        serialPort.openPort();

        SerialInputStream is = new SerialInputStream(serialPort);
        SerialOutputStream os = new SerialOutputStream(serialPort);

        new EchoOffObdCommand().run(is, os);
        new LineFeedOffObdCommand().run(is, os);
        new TimeoutObdCommand(100).run(is, os);
        new SelectProtocolObdCommand(ObdProtocols.AUTO).run(is, os);
        ThrottlePositionObdCommand tps = new ThrottlePositionObdCommand();
        tps.run(is, os);
        System.out.println(tps.getPercentage());        

    }
    catch (SerialPortException ex) {
        System.out.println(ex);
    }

}

////

  Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 2, Size: 0
at java.util.ArrayList.rangeCheck(ArrayList.java:635)
at java.util.ArrayList.get(ArrayList.java:411)
at pt.lighthouselabs.obd.commands.PercentageObdCommand.performCalculations(PercentageObdCommand.java:40)
at pt.lighthouselabs.obd.commands.ObdCommand.readResult(ObdCommand.java:114)
at pt.lighthouselabs.obd.commands.ObdCommand.run(ObdCommand.java:67)
at com.lukekrasner.carputer.Main.main(Main.java:40)
lkrasner commented 10 years ago

this was caused by a mistake on my side, sorry.

pires commented 10 years ago

No problem. I'm glad you're playing with the library! Feel free to get in touch if you need some help.