作者:ahao123 | 来源:互联网 | 2023-05-17 01:51
IgetthefollowingNullPointerExceptionwhentryingtoprintoutaprotocolbuffer:尝试打印协议缓冲区时,我收到以
I get the following NullPointerException when trying to print out a protocol buffer:
尝试打印协议缓冲区时,我收到以下NullPointerException:
Exception in thread "main" java.lang.NullPointerException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.google.protobuf.GeneratedMessage.invokeOrDie(GeneratedMessage.java:895)
at com.google.protobuf.GeneratedMessage.access$1400(GeneratedMessage.java:55)
at com.google.protobuf.GeneratedMessage$FieldAccessorTable$SingularEnumFieldAccessor.get(GeneratedMessage.java:1145)
at com.google.protobuf.GeneratedMessage.getField(GeneratedMessage.java:127)
at com.google.protobuf.GeneratedMessage.getAllFieldsMutable(GeneratedMessage.java:84)
at com.google.protobuf.GeneratedMessage.getAllFields(GeneratedMessage.java:119)
at com.google.protobuf.TextFormat.print(TextFormat.java:109)
at com.google.protobuf.TextFormat.print(TextFormat.java:64)
at com.google.protobuf.TextFormat.printToString(TextFormat.java:81)
at com.google.protobuf.AbstractMessage.toString(AbstractMessage.java:82)
at java.lang.String.valueOf(String.java:2826)
at java.io.PrintStream.println(PrintStream.java:771)
All I'm doing is printing out the protocol buffer, it's literally:
我正在做的就是打印出协议缓冲区,它的字面意思是:
NameOfProtocolBuffer.Builder a = NameOfProtocolBuffer.newBuilder();
// Set some fields....
NameOfProtocolBuffer b = a.build();
System.out.println(b); // etc.
All the fields of the protocol buffer either optional or repeated.
协议缓冲区的所有字段都是可选的或重复的。
Thanks for any help!
谢谢你的帮助!
1 个解决方案