0

谷歌为 App Engine 提供的教程是非常直接的复制粘贴代码,他们给你的代码是用来创建程序的。我负责将代码从名为 MainActivity.01 的文件复制到程序中的 MainActivity 文件中。这样做之后,出现一个错误,提示该方法未定义,但它是在后端项目下定义的,但未在我在客户端项目下创建的库中定义。如果有人熟悉本教程,我将执行修改客户端应用程序步骤。链接在这里

给我带来问题的代码是

protected Void doInBackground(Void... params) {
  CheckIn checkin = new CheckIn();

  checkin.setPlaceId("StoreNo123");//problem**************************

  Checkinendpoint.Builder builder = new Checkinendpoint.Builder(
      AndroidHttp.newCompatibleTransport(), new JacksonFactory(),
      null);

  builder = CloudEndpointUtils.updateBuilder(builder);

  Checkinendpoint endpoint = builder.build();


  try {
    endpoint.insertCheckIn(checkin).execute();
  } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
  }

  return null;
}`

该方法在后端项目中定义的类

package com.google.samplesolutions.mobileassistant;

import java.util.Date;

import com.google.appengine.api.datastore.Key;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

@Entity
public class CheckIn {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Key key;
    private String placeId;
    private String userEmail;
    private Date checkinDate;

    public Key getKey() {
        return key;
    }

    public String getPlaceId() {
        return placeId;
    }
    public void setPlaceId(String placeId) {
        this.placeId = placeId;
    }

    public String getUserEmail() {
        return userEmail;
    }
    public void setUserEmail(String userEmail) {
        this.userEmail = userEmail;
    }

    public Date getCheckinDate() {
        return checkinDate;
    }
    public void setCheckinDate(Date date) {
        checkinDate = date;
    }
}

和客户项目下的类

package com.google.samplesolutions.mobileassistant.checkinendpoint.model;

/**
 * Model definition for CheckIn.
 *
 * <p> This is the Java data model class that specifies how to   parse/serialize into the JSON that is
 * transmitted over HTTP when working with the checkinendpoint. For a detailed explanation see:
 * <a href="http://code.google.com/p/google-http-java-client/wiki/JSON">http://code.google.com/p/google-http-java-client/wiki/JSON</a>
 * </p>
 *
 * @author Google, Inc.
 */
@SuppressWarnings("javadoc")
public final class CheckIn extends com.google.api.client.json.GenericJson {

  @Override
  public CheckIn set(String fieldName, Object value) {
    return (CheckIn) super.set(fieldName, value);
  }

  @Override
  public CheckIn clone() {
    return (CheckIn) super.clone();
  }

}
4

0 回答 0