Retrofit2出現crash錯誤"Unable to create @Body converter for class "

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);
}

希望可以幫到有需要的人

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值