[置顶] protocol buffer使用中的问题This is supposed to be overridden by subclasses

测试protocol buffer格式数据输出工具类。用了protoc-2.4.1-win32生成的java类。然后测试项目中引入的包是

 <dependency>
    <groupId>com.google.protobuf</groupId>
    <artifactId>protobuf-java</artifactId>
    <version>2.5.0</version>
 </dependency

执行测试类的时候报下面的错误

Exception in thread "main" java.lang.UnsupportedOperationException: This is supposed to be overridden by subclasses.
    at com.google.protobuf.GeneratedMessage.getUnknownFields(GeneratedMessage.java:180)
    at com.test.utill.TextFormat$Printer.print(TextFormat.java:251)
    at com.test.utill.MessageLiteToStringUtil.toString(MessageLiteToStringUtil.java:20)
    at com.test.protocol.ProtocolTest.main(ProtocolTest.java:23)

后来发现是版本不一致的问题造成的,然后重新用protoc-2.5.0-win32根据.proto文件重新生成java文件,然后重新运行测试代码果然解决了问题
如下图

你可能感兴趣的:(buffer,protocol,格式)