我正在使用 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
提交
取消