1

I'm attempting to follow the example tutorial at https://developers.google.com/eclipse/docs/endpoints-addentities and I'm stuck figuring out how to get the GameEndpoint.Builder class to generate within Eclipse.

After following this and generating the cloud endpoints as described, I have a GameEndpoint class created, but there is no GameEndpoint.Builder class. So obviously I have this error

GameEndpoint.Builder cannot be resolved to a type

I'm stumped at this point. How do I generate the GameEndpoint.Builder class within Eclipse, or what would prevent it?

Code

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;
    }
}
4

3 回答 3

2

在观看了Google I/O 2013上使用 Android Studio 的视频后,我发现了我的问题,但它与 Eclipse 基本相同。

我遵循https://developers.google.com/eclipse/docs/endpoints-addentities的错误是您需要将实体类放入MyApp-AppEngine项目而不是MyApp项目。

这就是混乱的根源。如果它对未来的人有所帮助,这里是我所做的一个简短的细分。

  • 将您要添加到 App Engine的实体类放入您的MyApp-AppEngine项目中。
  • 右键单击您的课程并转到Google > Generate Cloud Endpoint Client Library
  • 右键单击您的MyApp-AppEngine项目并转到Google > Generate Cloud Enpoint Client Library
  • 将在您的项目中引用的MyApp项目中进行新的引用以供使用。
于 2013-05-25T02:43:40.810 回答
2

注意此答案基于 Android Studio,但我确信它与 Eclipse 几乎相同。

我也有这个问题,但后来找到了原因。原来我正在导入Endpoint我生成的类而不是端点 Api 包。让我说清楚。当您将端点模块添加到您的项目时,您会在端点包中获得MyBeanMyEndpoint类。如果您查看将客户端连接到后端的指南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(...)
于 2015-04-22T16:52:46.033 回答
1

我在 Android Studio 中遇到了同样的问题。我从实体 java bean 生成了 Endpoint 类,但是在创建 AsyncTask 时,现在可以获取 Builder。

实际上(如果我像你一样使用 Game java bean),Builder 并不依赖于 GameEndPoint,而是依赖于生成的 GameApi 类。

换句话说,我必须在 AsyncTask 类中添加这两个导入:

导入 com.examplepackage.backend.gameApi.GameApi;导入 com.examplepackage.backend.gameApi.model.Game;

而您编写的 Game java bean 和生成的 GameEndpoint 位于 com.examplepackage.backend 包下

于 2015-03-03T16:20:16.147 回答