protobuf-java - 方法 emptyIntList() 未定义
问题描述
我是Google Protobuf的新手。尝试使用下面的student.proto文件来玩它。
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;
}
然后我尝试使用下面的 Protobuf 编译器命令对其进行编译。从这里,我下载了编译器。
protoc -I=. --java_out=. ./student.proto
它成功编译并生成StudentDTO.java,但有错误。类内部使用了两种方法' emptyIntList() '和' newIntList() ',但它们没有被定义。
现在我的问题是如何解决这些错误或者我错过了什么?
解决方案
作为新手,我似乎在更新Protobuf Compiler时忘记了更新Google Protobuf Runtime。两个版本必须匹配。
这里有2个解决方案。
- Maven 用户- 在您的POM文件中包含以下依赖项。
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>x.y.z</version>
</dependency>
- 非 Maven 用户- 在类路径中包含protobuf-java-xyzjar。
推荐阅读
- html - 如何在文本框中显示错误消息,除了角度 8 中的数字/数字之外的任何其他内容
- asp.net - ASP.NET Core - 在所有路由上提供 index.html 而无需重写 URL
- python - 注释 YAML 文件中现有的键值对
- racket - 如何在 Racket 的函数中重新分配变量?
- python - How to correct Python-Tensorflow has no attribute error ''getdlopenflags'?
- reactjs - 带有 React 和 Docker 的 ASP.Net Core 2.2 或 3.1 SPA
- python - Flask and Pytest - PermissionError: [WinError 32] The process cannot access the file because it is being used by another process
- cmake - Cmake support for tasking tri-core compiler toolchain
- python - Xarray 按多次运行和时间分组
- three.js - Showing Point Cloud Structure using Lighting in Three.js