简体   繁体   中英

Found: 'java.util.Date', required: 'com.google.api.client.util.DateTime' GAE

I have writing backend for 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
}

And the endpoint is like

    @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;
    }

But when I try to call it from my android App like

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

it gives following error

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

I did a workspace level search and I could not find DateTime class anywhere. So where is this coming from. Also how did argument order change here ie first argument should have been of type UserDevice and 2nd of type Date?

Can you check if you have gdata-core.jar present under your project class path. This class is present under the said jar only. and instead of passing new java.util.Date() as parameter add the below code.

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

check this link for jar. Check the version as per your requirement.

hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM