Retrofit(2.0)入门小错误 -- Could not locate ResponseBody xxx Tried: * retrofit.BuiltInConverters
来源:互联网 发布:windows 更新git 编辑:程序博客网 时间:2024/05/16 11:40
前言
照例给出官网:Retrofit官网
学习资料:https://speakerdeck.com/jakewharton/simple-http-with-retrofit-2-droidcon-nyc-2015
其实大家学习的时候,完全可以按照官网Introduction,自己写一个例子来运行。但是百密一疏,官网可能忘记添加了一句非常重要的话,导致你可能出现如下错误:
Could not locate ResponseBody converter
错误信息:Caused by: java.lang.IllegalArgumentException: Could not locate ResponseBody converter for java.util.List<com.bzh.sampleretrofit.Repo>. Tried:* retrofit.BuiltInConvertersat retrofit.Retrofit.responseConverter(Retrofit.java:266)at retrofit.MethodHandler.createResponseConverter(MethodHandler.java:55)... 18 more
可以知道,是由于响应的结果在由Json转化为对象时出了错误。
解决
首先在gradle文件中引入依赖库。
compile 'com.squareup.retrofit:retrofit:2.0.0-beta2'compile 'com.squareup.retrofit:converter-gson:2.0.0-beta2' #使用Gson转化json串
其次在构建Retrofit
对象时,指明使用的Converter
工厂。
Retrofit retrofit = new Retrofit.Builder() .baseUrl("https://api.github.com") .addConverterFactory(GsonConverterFactory.create()) // 加上这句话 .build();
0 0
- Retrofit(2.0)入门小错误 -- Could not locate ResponseBody xxx Tried: * retrofit.BuiltInConverters
- Retrofit(2.0)入门小错误 -- Could not locate ResponseBody xxx Tried: * retrofit.BuiltInConverters
- Retrofit入门
- retrofit入门
- Retrofit入门
- Retrofit入门
- Retrofit
- Retrofit
- Retrofit
- Retrofit
- Retrofit
- Retrofit
- Retrofit
- Retrofit
- Retrofit
- Retrofit
- Retrofit
- Retrofit
- java synchronized详解
- 画图板的布局
- Android string.xml 显示特殊符号
- 高性能服务器设计——模块间通信
- Nginx 编译,添加未编译安装模块ngx_cache_purge
- Retrofit(2.0)入门小错误 -- Could not locate ResponseBody xxx Tried: * retrofit.BuiltInConverters
- Android上实现仿IOS的导航栏TitleBar
- C#获取windows串口号对应的串口(设备)名称
- 分布式系统的事务处理
- 字符编码笔记:ASCII,Unicode和UTF-8
- Android 模拟器genymotion安装,eclipse 插件
- Spring整合Struts2(实操)
- Webservice ,Http ,Ftp比较区别
- Jquery连续两次相同AJAX请求时,默认不执行本次;不同时终止上一次未完成的AJAX请求