Retrofit2出現crash錯誤"Unable to create @Body converter for class "
来源:互联网 发布:网络代刷平台 编辑:程序博客网 时间:2024/06/10 11:43
Retrofit2 的使用文章已經很多了,鴻洋,Hankkin博客已經寫得很清楚了,我今天試著用使用Retrofit2 結果
出現了一些問題,從網上找了很多沒有找到自己想要的.
我使用Retrofi 是測試登錄的,應為我的服務器只接受json提交形式,所有就不能用鍵值對上傳,這就要用到實體Bean,用實體Retrofit會自動幫轉為Json的,這個王jiji告訴我的.但是我用bean的時候還是會拋異常:”Unable to create @Body converter for class
查了很久才知道是哪裡有問題 :
compile 'com.google.code.gson:gson:2.3' compile 'com.squareup.retrofit2:converter-gson:2.0.2' compile 'com.squareup.retrofit2:retrofit:2.0.2'
這裡的版本converter和retrofit要保持一致,否則converter轉化json會異常,
主要的就是這些,順便貼下代碼:
User user = new User(); user.user_mobile = "13537635231"; user.user_paw = pwd; Retrofit retrofit = new Retrofit.Builder() .baseUrl("你的Base URl") .addConverterFactory(GsonConverterFactory.create()) .build(); APIService apiService = retrofit.create(APIService.class); Call<LoginInfo> login = apiService.login(user); login.enqueue(new Callback<LoginInfo>() { @Override public void onResponse(Call<LoginInfo> call, Response<LoginInfo> response) { System.out.println(response.body()); } @Override public void onFailure(Call<LoginInfo> call, Throwable t) { } });
public interface APIService { @POST("login") Call<LoginInfo> login(@Body User user);}
希望可以幫到有需要的人
0 0
- Retrofit2出現crash錯誤"Unable to create @Body converter for class "
- Unable to create converter for class`
- binbinyang--Unable to create converter for class
- vmware vcenter converter 4 FAILED: Unable to create a VSS snapshot of the source volume(s)
- Unable to load class for JSP
- Unable to compile class for JSP解决方案
- Unable to compile class for JSP
- Unable to load class for JSP
- Unable to compile class for JSP
- Unable to compile class for JSP
- Unable to compile class for JSP
- Unable to compile class for JSP
- Unable to compile class for JSP 解决办法
- Unable to compile class for JSP 解决方法
- Unable to compile class for JSP:
- Unable to compile class for JSP
- JavaWeb:Unable to compile class for JSP
- Unable to compile class for JSP
- CF_604B(二分+贪心)
- 《疯狂JAVA讲义》——聊天系统(1)
- 《SQL必知必会》16-18章笔记
- PHP array_multisort()函数多维数组排序
- textbox 加载文件
- Retrofit2出現crash錯誤"Unable to create @Body converter for class "
- mysql 获取自增值
- 问题记录:ubuntu中ssh配置
- 【Java 高并发】并发下的ArrayList&&HashMap
- 对Java的方法的理解
- 2016年人工智能十大发展趋势预测(2016年)
- Ubuntu环境下安装FFMPEG+SDL
- 他用10年前的攻击手法感染了近两万名开发者的电脑
- 第一次写项目的感觉 + 强行自我膨胀