Google为App Engine提供的教程是非常直接的复制粘贴代码,它们可以帮助您完成程序。我是将代码从名为MainActivity.01的文件复制到程序中的MainActivity文件的部分。执行此操作后出现错误,指出该方法未定义,但它是在后端项目下定义的,但未在我在客户端项目下创建的库中定义。如果有人熟悉我正在修改客户端应用程序步骤的教程。链接为here
给我提问的代码是
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();
}
}