简体   繁体   English

使用 Google 协议缓冲区的简单 java 文件的编译错误

[英]Compilation error of simple java files with Google Protocol Buffer

Google protocol buffer/java谷歌协议缓冲区/java

I am new to maven and Google Protocol Buffer.我是 maven 和 Google 协议缓冲区的新手。

I followed all the README instructions and successfully built the files with Maven.我按照所有 README 说明操作,并使用 Maven 成功构建了文件。

I got all the files in我得到了所有的文件

protobuf-2.4.1\java\target protobuf-2.4.1\java\target

(what is the use of this?) The test cases run fine. (这有什么用?)测试用例运行良好。

I compiled the meta data in the proto file and got the class files generated automatically here:我编译了 proto 文件中的元数据,并在此处自动生成了 class 文件:

com\example\tutorial\AddressBookProtos.java com\example\tutorial\AddressBookProtos.java

I created two java files: AddPerson.java and ListPeople.java from the code in the tutorial.我从教程中的代码创建了两个 java 文件:AddPerson.java 和 ListPeople.java。

日食截图

I am not able to execute it.我无法执行它。 Where did I go wrong?我在哪里 go 错了?

EDIT:编辑:

The method mergeFrom(Message) from the type AddressBookProtos.AddressBook.Builder refers to the missing type Message AddressBookProtos.AddressBook.Builder 类型中的方法 mergeFrom(Message) 引用缺少的类型 Message

the second error:第二个错误:

The method writeTo(CodedOutputStream) from the type AddressBookProtos.AddressBook refers to the missing type CodedOutputStream AddressBookProtos.AddressBook 类型中的 writeTo(CodedOutputStream) 方法指的是缺少的类型 CodedOutputStream

These are from the AddPerson.java这些来自 AddPerson.java

AddressBookProtos.java has 100's of errors AddressBookProtos.java 有 100 个错误

Looking at your screen shot it does not look like you have imported the generated classes to your project.查看您的屏幕截图,您似乎没有将生成的类导入您的项目。 Add all generated.java files to the correct location in your src folder and re-try.将所有生成的.java 文件添加到 src 文件夹中的正确位置,然后重试。

You have a compilation error.你有一个编译错误。 Hold your cursor over the error in the IDE (Eclipse) and post the error message.将 cursor 放在 IDE (Eclipse) 中的错误上方,然后发布错误消息。

First I don't know anything about this google project but anyways.首先,我对这个谷歌项目一无所知,但无论如何。 If its maven try this in the command prompt where your pom.xml is.如果它的 maven 在你的 pom.xml 所在的命令提示符下试试这个。

mvn eclipse:eclipse

It should generate project files then import the project in eclipse.它应该生成项目文件,然后将项目导入 eclipse。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM