英文:
Only one HTTP method is allowed. Found GET and PUT
问题
java.lang.IllegalArgumentException: 只允许一个HTTP方法。发现:GET 和 PUT。
对于方法 ApiInterface.UpdateCoordinates
我已经尝试了最后2个小时来更新坐标,但它不起作用,一直抛出这个错误
java.lang.IllegalArgumentException: 只允许一个HTTP方法。发现:GET 和 PUT。
对于方法 ApiInterface.UpdateCoordinates
在 retrofit2.Utils.methodError(Utils.java:52) 处
在 retrofit2.Utils.methodError(Utils.java:42) 处
在 retrofit2.RequestFactory$Builder.parseHttpMethodAndPath(RequestFactory.java:251) 处
在 retrofit2.RequestFactory$Builder.parseMethodAnnotation(RequestFactory.java:224) 处
在 retrofit2.RequestFactory$Builder.build(RequestFactory.java:171) 处
在 retrofit2.RequestFactory.parseAnnotations(RequestFactory.java:67) 处
在 retrofit2.ServiceMethod.parseAnnotations(ServiceMethod.java:26) 处
在 retrofit2.Retrofit.loadServiceMethod(Retrofit.java:170) 处
在 retrofit2.Retrofit$1.invoke(Retrofit.java:149) 处
在 java.lang.reflect.Proxy.invoke(Proxy.java:1006) 处
在 $Proxy0.UpdateCoordinates(Unknown Source) 处
在 com.example.charlo.jkuat_mobile_app.util.LocationService$1.onLocationResult(LocationService.java:54) 处
>模型类
更新模型类
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;
}
}
>模型类
数据模型类
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) {
}
});
英文:
java.lang.IllegalArgumentException: Only one HTTP method is allowed. Found: GET and PUT.
for method ApiInterface.UpdateCoordinates
i have tried for the last 2 hours to update the coordinates but it ain't working keeps throwing this error
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;
}
}
Interface
interface class
@PUT("update_driver/{dispatchid}?")
Call<GpsUpdate> UpdateCoordinates(@Path("dispatchid") int id, @Field("latitude") String latitude, @Field("longitude") String longitude );
location service class
the update class which sends the coordinates to the backend
@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) {
}
});
答案1
得分: 0
我认为我应该将这标记为重复:
尝试将
@Path("dispatchid") int id
更改为
@Path("dispatchid") int dispatchid
英文:
I think I should have marked this as a duplicate:
Try changing the
@Path("dispatchid") int id
to
@Path("dispatchid") int dispatchid
专注分享java语言的经验与见解,让所有开发者获益!
评论