The method emptyIntList() is undefined

被刻印的时光 ゝ 提交于 2019-12-24 10:24:42

问题


I am new to Google Protobuf. Tried to play with it using below student.proto file.

syntax = "proto3";
package rld;

option java_package = "com.rld";
option java_outer_classname = "StudentDTO";

message Student {
    string name = 1;
    int32 roll = 2;  
    repeated int32 mark = 3; //Marks in various subjects
}

message StudentDatabase {
  repeated Student student = 1;
}

Then I tried to compile it using below Protobuf compiler command. From here, I downloaded the compiler.

protoc -I=. --java_out=. ./student.proto

It compiled successfully and generated StudentDTO.java, but with errors. There are two methods 'emptyIntList()' and 'newIntList()' used inside the class, but they aren't defined.

Now my question is how to resolve those errors or am I missing something?


回答1:


Being new, it seems I had forgotten to update Google Protobuf Runtime while updating Protobuf Compiler. Both the versions must match.

Here are 2 solutions.

  1. Maven Users - Include the following dependency in your POM file.
    <dependency>
      <groupId>com.google.protobuf</groupId>
      <artifactId>protobuf-java</artifactId>
      <version>x.y.z</version>
    </dependency>
  1. Non Maven Users - Include the protobuf-java-x.y.z.jar in your classpath.


来源:https://stackoverflow.com/questions/55421031/the-method-emptyintlist-is-undefined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!