有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java只允许使用一种HTTP方法。找到,得到,放

爪哇。lang.IllegalArgumentException:只允许使用一个HTTP方法。发现:获取并放置。 用于方法接口。更新坐标 在过去的两个小时里,我一直在尝试更新坐标,但不起作用。我一直在抛出这个错误

java.lang.IllegalArgumentException: Only one HTTP method is allowed. Found: GET and PUT.
        for method ApiInterface.UpdateCoordinates
        at retrofit2.Utils.methodError(Utils.java:52)
        at retrofit2.Utils.methodError(Utils.java:42)
        at retrofit2.RequestFactory$Builder.parseHttpMethodAndPath(RequestFactory.java:251)
        at retrofit2.RequestFactory$Builder.parseMethodAnnotation(RequestFactory.java:224)
        at retrofit2.RequestFactory$Builder.build(RequestFactory.java:171)
        at retrofit2.RequestFactory.parseAnnotations(RequestFactory.java:67)
        at retrofit2.ServiceMethod.parseAnnotations(ServiceMethod.java:26)
        at retrofit2.Retrofit.loadServiceMethod(Retrofit.java:170)
        at retrofit2.Retrofit$1.invoke(Retrofit.java:149)
        at java.lang.reflect.Proxy.invoke(Proxy.java:1006)
        at $Proxy0.UpdateCoordinates(Unknown Source)
        at com.example.charlo.jkuat_mobile_app.util.LocationService$1.onLocationResult(LocationService.java:54)

Model classes the update model class import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName;

public class GpsUpdate {

    @SerializedName("success")
    @Expose
    private Boolean success;
    @SerializedName("data")
    @Expose
    private Data data;
    @SerializedName("message")
    @Expose
    private String message;

    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public Data getData() {
        return data;
    }

    public void setData(Data data) {
        this.data = data;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

}

model class the data model class

import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

public class Data {
    @SerializedName("id")
    @Expose
    private Integer id;
    @SerializedName("driverid")
    @Expose
    private Integer driverid;
    @SerializedName("companyid")
    @Expose
    private Integer companyid;
    @SerializedName("vehicleid")
    @Expose
    private Integer vehicleid;
    @SerializedName("warehouseid")
    @Expose
    private Integer warehouseid;
    @SerializedName("orders")
    @Expose
    private Integer orders;
    @SerializedName("status")
    @Expose
    private Integer status;
    @SerializedName("latitute")
    @Expose
    private String latitute;
    @SerializedName("longitude")
    @Expose
    private String longitude;
    @SerializedName("tripdate")
    @Expose
    private String tripdate;
    @SerializedName("created_at")
    @Expose
    private String createdAt;
    @SerializedName("updated_at")
    @Expose
    private String updatedAt;


    public Data(String latitute, String longitude) {
        this.latitute = latitute;
        this.longitude = longitude;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getDriverid() {
        return driverid;
    }

    public void setDriverid(Integer driverid) {
        this.driverid = driverid;
    }

    public Integer getCompanyid() {
        return companyid;
    }

    public void setCompanyid(Integer companyid) {
        this.companyid = companyid;
    }

    public Integer getVehicleid() {
        return vehicleid;
    }

    public void setVehicleid(Integer vehicleid) {
        this.vehicleid = vehicleid;
    }

    public Integer getWarehouseid() {
        return warehouseid;
    }

    public void setWarehouseid(Integer warehouseid) {
        this.warehouseid = warehouseid;
    }

    public Integer getOrders() {
        return orders;
    }

    public void setOrders(Integer orders) {
        this.orders = orders;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getLatitute() {
        return latitute;
    }

    public void setLatitute(String latitute) {
        this.latitute = latitute;
    }

    public String getLongitude() {
        return longitude;
    }

    public void setLongitude(String longitude) {
        this.longitude = longitude;
    }

    public String getTripdate() {
        return tripdate;
    }

    public void setTripdate(String tripdate) {
        this.tripdate = tripdate;
    }

    public String getCreatedAt() {
        return createdAt;
    }

    public void setCreatedAt(String createdAt) {
        this.createdAt = createdAt;
    }

    public String getUpdatedAt() {
        return updatedAt;
    }

    public void setUpdatedAt(String updatedAt) {
        this.updatedAt = updatedAt;
    }

}

接口 接口类

@PUT("update_driver/{dispatchid}?")
        Call<GpsUpdate> UpdateCoordinates(@Path("dispatchid") int id, @Field("latitude") String latitude, @Field("longitude") String longitude );

位置服务类 将坐标发送到后端的更新类

@Override
    public void onCreate() {
        super.onCreate();
        fusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this);
        tokenManager = TokenManager.getInstance(getSharedPreferences("prefs", MODE_PRIVATE));
        service = ApiClient.createService(ApiInterface.class);
        locationCallback = new LocationCallback(){
            @Override
            public void onLocationResult(LocationResult locationResult) {
                super.onLocationResult(locationResult);
                double lat = locationResult.getLastLocation().getLatitude();
                double lng = locationResult.getLastLocation().getLongitude();
                String latitude = String.valueOf(lat);
                String longitude = String.valueOf(lng);

                Data data = new Data(latitude,longitude);

                Call<GpsUpdate> call = service.UpdateCoordinates(tokenManager.getToken().getDispatchid(),data.getLatitute(), data.getLongitude());
                call.enqueue(new Callback<GpsUpdate>() {
                    @Override
                    public void onResponse(Call<GpsUpdate> call, Response<GpsUpdate> response) {

                    }

                    @Override
                    public void onFailure(Call<GpsUpdate> call, Throwable t) {

                    }
                });

共 (0) 个答案