问题
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.
- 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>
- Non Maven Users - Include the protobuf-java-x.y.z.jar in your classpath.
来源:https://stackoverflow.com/questions/55421031/the-method-emptyintlist-is-undefined