我已经为Google App Engine编写了后端
import com.googlecode.objectify.annotation.Entity;
import com.googlecode.objectify.annotation.Id;
import com.googlecode.objectify.annotation.Index;
import java.util.Date;
@Entity
public class DeviceData {
/**
* Unique identifier of this Entity in the database.
*/
@Id
private Long key;
@Index
private UserDevice device;
public Date date;
//getters and setters
}
端点就像
@ApiMethod(httpMethod = "POST")
public final DeviceData updateDeviceData(UserDevice device,@Named("date") Date date, User user) throws ServiceException {
DeviceData newDeviceLocation = new DeviceData();
newDeviceLocation.setDevice(device);
newDeviceLocation.setLatitude(latitude);
newDeviceLocation.setLongitude(longitude);
newDeviceLocation.setDate(date);
OfyService.ofy().save().entity(newDeviceLocation).now();
return newDeviceLocation;
}
但是当我尝试从我的Android应用程序中调用它时
deviceLocatorApi.devicedata().updateDeviceData(new Date(), userDevice).execute();
它出现以下错误
找到:'java.util.Date',必填:'com.google.api.client.util.DateTime'更多.. 错误:(49,45)错误:类DeviceLocator.Devicedata中的方法updateDeviceData无法应用于给定类型; required:DateTime,UserDevice 发现:Date,UserDevice reason:实际参数Date无法通过方法调用转换转换为DateTime
我进行了工作区级别搜索,但我无法在任何地方找到DateTime
课程。那么这是从哪里来的。参数顺序如何在这里改变,即第一个参数应该是UserDevice类型和第二个类型Date?
答案 0 :(得分:1)
您可以检查项目类路径下是否存在gdata-core.jar。该类仅存在于所述罐下。而不是传递新的java.util.Date()作为参数添加以下代码。
deviceLocatorApi.devicedata().updateDeviceData(new DateTime(new java.util.Date()), userDevice).execute();
检查此link是否为jar。根据您的要求检查版本。
希望这有帮助!