我有了提交屍信息使用Retrofit2服務器客戶端應用程序,服務器端是好的,在我的客戶端應用程序,但是我很出現錯誤我不明白,請幫助。Retrofit2,java.lang.StackOverflowError的不能轉換到了java.lang.RuntimeException
這裏是我的接口
public interface CorpseServiceInterface {
@Headers({
"Accept: application/json",
"Content-Type: application/json"
})
@POST("corpses")
Call<Corpse> save(@Body Corpse player);
}
而且波紋管
public class CorpseService {
private CorpseServiceInterface server;
public CorpseService(DAO<Corpse> dao) {
this.dao = dao;
final OkHttpClient okHttpClient = new OkHttpClient.Builder()
.readTimeout(60, TimeUnit.SECONDS)
.connectTimeout(60, TimeUnit.SECONDS)
.build();
Gson gson = new GsonBuilder()
.excludeFieldsWithModifiers(Modifier.FINAL, Modifier.TRANSIENT, Modifier.STATIC)
.create();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(API.API_URL)
.addConverterFactory(GsonConverterFactory.create(gson))
.client(okHttpClient)
.build();
server = retrofit.create(CorpseServiceInterface.class);
}
public void save(Corpse corpse) {
Call<Corpse> call = server.save(corpse);
call.enqueue(new Callback<Corpse>() {
@Override
public void onResponse(Call<Corpse> call, Response<Corpse> response) {
System.out.println("Success");
}
@Override
public void onFailure(Call<Corpse> call, Throwable t) {
Request request = call.request();
System.out.println("Request Url: " + request.url());
System.out.println("onFailure: " + t.toString());
}
});
}
}
這是我得到的錯誤實施:
java.lang.ClassCastException: java.lang.StackOverflowError cannot be cast to java.lang.RuntimeException
at retrofit2.OkHttpCall.request(OkHttpCall.java:63)
at lfs.mortuary.CorpseService$1.onFailure(CorpseService.java:59)
at retrofit2.OkHttpCall.enqueue(OkHttpCall.java:99)
at lfs.mortuary.CorpseService.save(CorpseService.java:50)
at lfs.common.DAO.save(DAO.java:54)
at fastfx.view.InputFormDialog.saveOrUpdate(InputFormDialog.java:155)
at fastfx.view.InputFormDialog.lambda$0(InputFormDialog.java:131)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
的錯誤是在把一個調試斷點,有那麼您可以檢查原有的StackOverflowError線63甩在了'retrofit2.OkHttpCall'類。 – toongeorges