找到:'java.util.Date',需要:'com.google.api.client.util.DateTime' GAE

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();

它给出以下错误

Found: 'java.util.Date', required: 'com.google.api.client.util.DateTime' more.. Error:(49, 45) error: method updateDeviceData in class DeviceLocator.Devicedata cannot be applied to given types; required: DateTime,UserDevice found: Date,UserDevice reason: actual argument Date cannot be converted to DateTime by method invocation conversion

我进行了工作区级别的搜索,但在任何地方都找不到 DateTime class。那么这是从哪里来的。还有这里的参数顺序是如何改变的,即第一个参数应该是 UserDevice 类型,第二个参数应该是 Date 类型?

你能检查一下你的项目 class 路径下是否有 gdata-core.jar 吗?此 class 仅存在于所述罐子下。而不是将 new java.util.Date() 作为参数传递,而是添加以下代码。

deviceLocatorApi.devicedata().updateDeviceData(new DateTime(new java.util.Date()), userDevice).execute();

检查此 link 是否有 jar。根据您的要求检查版本。

希望对您有所帮助!