Question

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;
    }
}
Was it helpful?

Solution

I figured out my issue after watching this video from Google I/O 2013 which is using Android Studio, but it was the same thing as Eclipse mostly.

My mistake in following https://developers.google.com/eclipse/docs/endpoints-addentities was that you need to put your entity class into the MyApp-AppEngine project and NOT your MyApp project.

That was the source of confusion. In case it helps those in the future, here is a short breakdown of what I did.

  • Put the Entity class you want to add to App Engine into your MyApp-AppEngine project.
  • Right click your class and go to Google > Generate Cloud Endpoint Client Library
  • Right click your MyApp-AppEngine project and go to Google > Generate Cloud Enpoint Client Library
  • New references will be made in your MyApp project which you reference in your project for usage.

OTHER TIPS

Note This answer is based on Android Studio, but am sure it's pretty much the same as Eclipse.

I also had this issue but later found the cause.Turns out I was importing the Endpoint class I generated instead of the endpoint Api package. Let me be clear.When you add the endpoint module to your project, you get the MyBean and MyEndpoint classes in the endpoint package. If you take a look at the guide to connecting your client to your backend, the EndpointsAsyncTask class uses:

private static MyApi myApiService = null;

Note how it uses MyApi instead of MyBean Now I was wondering where it got that from but I just have to take a look at my backend libraries:

enter image description here

The library marked 1 is the library first added to your project when you follow the guide previously mentioned. When I added a new class Student and autogenerated the cloud endpoint class, the second library was also added.

Long, boring story short; It is this library you should be importing and not the class.

import com.package-name.backend.studentApi.StudentApi;

and then using:

private static StudentApi myApiService = null;
...
StudentApi.Builder builder = new StudentApi.Builder(...)

instead of:

import com.package-name.backend.StudentEndpoint;
 ...
private static StudentEndpoint myApiService = null;

StudentEndpoint.Builder builder = new StudentEndpoint.Builder(...)

I got the same problem in Android Studio. I generated my Endpoint class from my entity java bean but when creating the AsyncTask, now way to get the Builder.

Actually (if I take a Game java bean like you) the Builder is not depending on the GameEndPoint but on the generated GameApi class.

In other words, I had to add these two imports in the AsyncTask class:

import com.examplepackage.backend.gameApi.GameApi; import com.examplepackage.backend.gameApi.model.Game;

while the Game java bean that you wrote and the generated GameEndpoint are under package com.examplepackage.backend

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top