[英]Incompatible types: com.google.api.client.util.DateTime cannot be converted to org.joda.time.DateTime
[英]Found: 'java.util.Date', required: 'com.google.api.client.util.DateTime' GAE
我为 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 不能应用于给定类型; 需要:DateTime,UserDevice 找到:Date,UserDevice 原因:实参Date不能通过方法调用转换转换为DateTime
我进行了工作区级别的搜索,但在任何地方都找不到DateTime
类。 那么这是从哪里来的。 另外这里的参数顺序是如何改变的,即第一个参数应该是 UserDevice 类型,第二个参数应该是 Date 类型?
你能检查一下你的项目类路径下是否有 gdata-core.jar 。 此类仅存在于所述罐子下。 而不是传递新的 java.util.Date() 作为参数添加以下代码。
deviceLocatorApi.devicedata().updateDeviceData(new DateTime(new java.util.Date()), userDevice).execute();
检查此链接以获取 jar。 根据您的要求检查版本。
希望这可以帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.