我正在使用 Protobuff 構建我的 Java 對象,為什么java.lang.IndexOutOfBoundsException: Index: 0, Size: 0在調用setHeader(0, h1)我的代碼時總是收到異常。這是我的代碼: Person.Header h1 = Person.Header.newBuilder() .setKey("Key1") .setValue("value1") .build(); Person person = Person.newBuilder() .setBody("TestBody") .setHeader(0, h1) .build();這是我的 protobuff 消息(調用 dataformat.proto):syntax = "proto3";package tutorial;option java_package = "tutorial";message Person { string body = 1; repeated Header header = 2; message Header { string key = 3; string value = 4; }}堆棧跟蹤:java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 at java.util.ArrayList.set(ArrayList.java:453) at com.google.protobuf.ProtobufArrayList.set(ProtobufArrayList.java:96) at tutorial.Dataformat$Person.setHeader(Dataformat.java:572) at tutorial.Dataformat$Person.access$1200(Dataformat.java:42) at tutorial.Dataformat$Person$Builder.setHeader(Dataformat.java:815)
添加回答
舉報
0/150
提交
取消