No-args constructor for class does not exist. Register an InstanceCreator with G
2015-09-28 09:21
721 查看
有时候我们在使用Googel官方的json解析包时,如果自己的实体类中出现代参的构造函数.在1.4的jar中,如果类造型中有参数,就会调用不了无参构造器,(如:HashMap的构造器就会有参数)
参考博文内容:
有时候我们在使用Googel官方的json解析包时,如果自己的实体类中出现代参的构造函数,如;
public class InformationSummary {
/**
* id
*/
public String id;
/**
* 栏目名称
*/
public String name;
/**
* 栏目图片
*/
public String picture;
/**
* 栏目内容
*/
public String content;
/**
* 新闻头条id
*/
public String newsId;
/**
* 子业务编码
*/
public String subCode;
public InformationSummary(String id, String name, String picture, String content) {
super();
this.id = id;
this.name = name;
this.picture = picture;
this.content = content;
}
如果这样写的话,有时候会报这样的错误;
06-26 17:08:59.723: W/System.err(4724): java.lang.RuntimeException: No-args constructor for class com.funo.health.bean.business.InformationSummary does not exist. Register an InstanceCreator with Gson for this type to fix this problem.
06-26 17:08:59.723: W/System.err(4724): at com.google.gson.MappedObjectConstructor.constructWithNoArgConstructor(MappedObjectConstructor.java:64)
简单认识就是我们自己写了构造函数后,本身自带的无参就会忽略,但是json.jar包中的Gson,需要!简单方法就是加上午参数构造函数!
参考地址: http://www.tuicool.com/articles/v6b2Mb
http://javaeedyc.iteye.com/blog/1894799
参考博文内容:
有时候我们在使用Googel官方的json解析包时,如果自己的实体类中出现代参的构造函数,如;
public class InformationSummary {
/**
* id
*/
public String id;
/**
* 栏目名称
*/
public String name;
/**
* 栏目图片
*/
public String picture;
/**
* 栏目内容
*/
public String content;
/**
* 新闻头条id
*/
public String newsId;
/**
* 子业务编码
*/
public String subCode;
public InformationSummary(String id, String name, String picture, String content) {
super();
this.id = id;
this.name = name;
this.picture = picture;
this.content = content;
}
如果这样写的话,有时候会报这样的错误;
06-26 17:08:59.723: W/System.err(4724): java.lang.RuntimeException: No-args constructor for class com.funo.health.bean.business.InformationSummary does not exist. Register an InstanceCreator with Gson for this type to fix this problem.
06-26 17:08:59.723: W/System.err(4724): at com.google.gson.MappedObjectConstructor.constructWithNoArgConstructor(MappedObjectConstructor.java:64)
简单认识就是我们自己写了构造函数后,本身自带的无参就会忽略,但是json.jar包中的Gson,需要!简单方法就是加上午参数构造函数!
参考地址: http://www.tuicool.com/articles/v6b2Mb
http://javaeedyc.iteye.com/blog/1894799
相关文章推荐
- MMM(双主多从)+Amoeba 整合 MySQl读写分离集群架构
- 谷歌官方Gradle文档
- ubuntu 安装jdk
- Android实战简易教程<三十三>(自定义View实现控件晃动提示效果)
- Android实战简易教程<三十四>(基于ViewPager和FragmentPagerAdapter实现滑动通用Tab)
- 转:嵌入式软件工程师经典笔试题
- 如何为Apache JMeter开发插件(三)——冲破图片验证码的束缚
- codeforces 580D. Kefa and Dishes dp
- 1012. 数字分类 (20)
- Android实战简易教程<三十五>(将二维码扫描和生成Demo引入项目实例)
- Android实战简易教程<三十六>(监听短信-实现短信验证码自动填入)
- 焦点在文本框的最右边
- 专业实训题目需求分析
- 禁用网络适配器时出现“此时无法停用,这个链接可能在用一个或多个不支持即插即用的协议”
- oracle sql查询大全
- 用模式匹配解析 URL
- linux状态及原理全剖析
- 火云开发课堂 - 《Shader从入门到精通》系列 第九节:在Shader中实现马赛克滤镜
- Android实战简易教程<三十七>(ListView中点击button跳转到拨号界面实例)
- 王垠Linux长篇论