Я пытаюсь использовать метод GET для отображения данных моего продукта в макете. Я могу загрузить продукт, используя метод POST, он работает нормально, но с помощью GET не работает, вот мой код для интерфейса ApiService
Я получаю эту ошибку от l
Java
public interface ApiService {
@Multipart
@POST("/se/product")
/* @Headers("Content-Type: application/json")*/
Call<Product> saveProduct(@Part List<MultipartBody.Part> file, @Part("name") RequestBody name, @Part("price") RequestBody price, @Part("quantity") RequestBody quantity, @Part("idCategory") RequestBody idCategory,
@Part("model") RequestBody model, @Header("Authorization") String token);
@GET("/se/product/{productId}")
Call<Product> getProduct(@Body RequestBody id,@Header("Authorization") String token);
// @GET("/se/product/{productId}")
// public void getProductDetails(@Part("product_id") String product_id, Callback<Product> callback);
}
и это мой класс для продукта
public class ProductsDetails extends AppCompatActivity {
ApiService chuckService;
TextView price,quantity,model,name;
ImageView file;
String token;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_product_details);
name = (TextView) findViewById(R.id.name);
model = (TextView) findViewById(R.id.model);
price = (TextView) findViewById(R.id.price);
quantity = (TextView) findViewById(R.id.quantity);
file = (ImageView) findViewById(R.id.file);
ApiService chuckService = Okhttp_RetrofitClient.getClient().create(ApiService.class);
JSONObject paramObject = new JSONObject();
RequestBody body = RequestBody.create(MediaType.parse("text/plain"), String.valueOf((paramObject)));
Call<Product> call = chuckService.getProduct(body,token);
call.enqueue(new Callback<Product>() {
@Override
public void onResponse(Call<Product> call,
Response<Product> response) {
name.setText(response.body().getName());
price.setText(response.body().getPrice());
quantity.setText(response.body().getQuantity());
model.setText(response.body().getModel());
Picasso.with(getApplicationContext()).load(response.body().getFile()).
into(file);
}
@Override
public void onFailure(Call<Product> call, Throwable
t) {
name.setText(t.getMessage());
}
});
}
}
вот мой POJO для продукта
public class Product {
@Override
public String toString() {
return "Product{" +
"id=" + id +
", quantity=" + quantity +
", idCategory=" + idCategory +
", name='" + name + '\'' +
", model='" + model + '\'' +
", published=" + published +
", price=" + price +
'}';
}
private String productId;
public String getProductId() {
return productId;
}
public void setProductId(String productId) {
this.productId = productId;
}
public List<String> getImages() {
return images;
}
public void setImages(List<String> images) {
this.images = images;
}
private List<String> images = null;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
private Integer id;
@SerializedName("quantity")
@Expose
private String quantity;
@SerializedName("idCategory")
@Expose
private Integer idCategory;
public String getQuantity() {
return quantity;
}
@SerializedName("name")
@Expose
private String name;
@SerializedName("model")
@Expose
private String model;
public void setQuantity(String quantity) {
this.quantity = quantity;
}
public Integer getIdCategory() {
return idCategory;
}
public void setIdCategory(Integer idCategory) {
this.idCategory = idCategory;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public boolean isPublished() {
return published;
}
public void setPublished(boolean published) {
this.published = published;
}
public Integer getPrice() {
return price;
}
public void setPrice(Integer price) {
this.price = price;
}
public String getFile() {
return file;
}
public void setFile(String file) {
this.file = file;
}
@SerializedName("published")
@Expose
private boolean published;
@SerializedName("price")
@Expose
private Integer price;
@SerializedName("file")
@Expose
private String file;
}
здесь xml чтобы увидеть подробности продукта
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<RelativeLayout
android:id="@+id/detail_product"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp">
<LinearLayout
android:layout_width="375dp"
android:layout_height="409dp"
android:layout_marginStart="5dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="5dp"
android:layout_marginRight="5dp"
android:layout_marginBottom="5dp"
android:orientation="vertical">
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="Nom du produit"
android:textColor="@android:color/black"
android:textSize="20sp"
android:textStyle="italic" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_weight="2"
android:orientation="horizontal">
<ImageView
android:id="@+id/file"
android:layout_width="50dp"
android:layout_height="202dp"
android:layout_margin="5dp"
android:layout_weight="1" />
<TextView
android:id="@+id/model"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_weight="1"
android:text="Details"
android:textAlignment="textStart"
android:textColor="@android:color/black"
android:textSize="12sp" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="Cfa. 190.000"
android:textColor="@android:color/black"
android:textSize="20sp"
android:textStyle="italic" />
<TextView
android:id="@+id/quantity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_toRightOf="@id/price"
android:text="Quantite"
android:textColor="@android:color/black"
android:textSize="20sp" />
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
Stacktrace
Caused by: java.lang.IllegalArgumentException: Non-body HTTP method cannot contain @Body. for method
ApiService.getProduct at
retrofit2.ServiceMethod$Builder.methodError(ServiceMethod.java:755) at com.monsokoseller.app.Activities.ProductsDetails.onCreate(ProductsDetails.java:50)