![](/img/trans.png)
[英]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.