我正在尝试按照https://developers.google.com/eclipse/docs/endpoints-addentities上的示例教程进行操作,并且我很难弄清楚如何在Eclipse中生成GameEndpoint.Builder
类。
在完成此操作并按照描述生成云端点后,我创建了一个GameEndpoint
类,但没有GameEndpoint.Builder
类。显然我有这个错误
GameEndpoint.Builder无法解析为类型
我在这一点上很难过。如何在Eclipse中生成GameEndpoint.Builder
类,或者什么会阻止它?
代码
public class NewGameTask extends AsyncTask<Context, Integer, Long> {
protected Long doInBackground(Context... contexts) {
GameEndpoint.Builder endpointBuilder = new GameEndpoint.Builder(
AndroidHttp.newCompatibleTransport(), new JacksonFactory(),
new HttpRequestInitializer() {
public void initialize(HttpRequest httpRequest) {
}
});
GameEndpoint endpoint = CloudEndpointUtils.updateBuilder(
endpointBuilder).build();
try {
Game game = new Game();
game.setStart(Calendar.getInstance());
Game result = endpoint.insertGame(game);
} catch (IOException e) {
e.printStackTrace();
}
return (long) 0;
}
}
答案 0 :(得分:2)
我在使用Android Studio的Google I/O 2013观看此视频后发现了我的问题,但它与Eclipse的内容基本相同。
我在跟踪https://developers.google.com/eclipse/docs/endpoints-addentities时的错误是您需要将实体类放入 MyApp-AppEngine 项目而不是 MyApp 项目。
这是混乱的根源。如果它在将来帮助那些人,这里是我所做的简短细分。
答案 1 :(得分:2)
注意这个答案基于Android Studio,但我相信它与Eclipse几乎相同。
我也有这个问题,但后来找到了原因。转出我导入了我生成的Endpoint
类,而不是端点Api包。让我说清楚。当您将端点模块添加到项目中时,您将获得端点包中的MyBean
和MyEndpoint
类。如果您查看guide以将客户端连接到后端,EndpointsAsyncTask
类将使用:
private static MyApi myApiService = null;
请注意它如何使用MyApi
代替MyBean
现在我想知道它是从哪里获得的,但我只需要查看我的后端库:
标记为1
的库是您按照前面提到的指南首次添加到项目中的库。当我添加新类Student
并自动生成云端点类时,还添加了第二个库。
冗长乏味的故事;你应该导入这个库而不是类。
import com.package-name.backend.studentApi.StudentApi;
然后使用:
private static StudentApi myApiService = null;
...
StudentApi.Builder builder = new StudentApi.Builder(...)
而不是:
import com.package-name.backend.StudentEndpoint;
...
private static StudentEndpoint myApiService = null;
StudentEndpoint.Builder builder = new StudentEndpoint.Builder(...)
答案 2 :(得分:1)
我在Android Studio中遇到了同样的问题。我从我的实体java bean生成了我的Endpoint类,但在创建AsyncTask时,现在可以获得Builder。
实际上(如果我像你一样使用Game java bean),Builder不依赖于GameEndPoint,而是依赖于生成的GameApi类。
换句话说,我必须在AsyncTask类中添加这两个导入:
import com.examplepackage.backend.gameApi.GameApi; import com.examplepackage.backend.gameApi.model.Game;
虽然您编写的Game java bean和生成的GameEndpoint位于包com.examplepackage.backend
之下