タイトルの内容でうまくいかず困っています。
[https://futurestud.io/tutorials/retrofit-send-objects-in-request-body]
上のリンクのページを参考にコードを書いたのですが、
Non-static method createRequest(fooReq) can not be referenced from a static context
と言われてしまい上手く行きませんでした。
コードは以下になります。
MainActivity
Java
1 FooRequest fr = new FooRequest(foo, bar); 2 Call<FooRequest> call = ApiService.createRequest(fr); 3 call.enqueue(new Callback<FooRequest>() { 4 @Override 5 public void onResponse(Call<FooRequest> call, retrofit2.Response<FooRequest> response) { 6 7 } 8 9 @Override 10 public void onFailure(Call<FooRequest> call, Throwable t) { 11 12 } 13 });
ApiService
Java
1public interface ApiService { 2 @POST("./") 3 Call<FooRequest> createRequest(@Body FooRequest fr); 4}
FooRequest
java
1public class FooRequest { 2 final String foo; 3 final String bar; 4 5 FooRequest(String foo, String bar) { 6 this.foo = foo; 7 this.bar = bar; 8 } 9 10}
Javaにも不慣れなため、初歩的な問題かもしれませんが、上手い方法がありましたら教えてください。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/10/21 10:24