Search code examples
androidserializationandroid-3.0-honeycombkryo

Exception only on Android 3.0


I am using Kryonet for an Android app, and works perfectly on all Android versions but the 3.0 version. I am getting the following exception:

E/AndroidRuntime(16861): FATAL EXCEPTION: Thread-30
E/AndroidRuntime(16861): com.esotericsoftware.kryo.KryoException: java.lang.StringIndexOutOfBoundsException: start=0 end=5 data.length=512 index=6 length=5
E/AndroidRuntime(16861): Serialization trace:
E/AndroidRuntime(16861): email (com.momasoft.sudokutournament.network.Network$Login)
E/AndroidRuntime(16861): at com.esotericsoftware.kryo.serializers.FieldSerializer.write(FieldSerializer.java:203)

Why does this happen only on Android 3.0? Is there a way to solve it?

Thank you!


Solution

  • I found a solution, debugging the Kryo library: I suggest to change the following code from kryo:

    com.esotericsoftware.kryo.io.Output.java:307

    /***Change this: ***/
    value.getBytes(0, charCount, buffer, position);
    position += charCount;
    
    /***for this: ***/
    byte[] valueB = value.getBytes();
    for (int j = 0; j < valueB.length; j++) {
       this.writeByte(valueB[j]);
    }
    

    the getBytes(int start, int end, byte[] elem, int offset) is deprecated, and gives problems in android 3.0.