`

No-args constructor for class does not exist. Register an InstanceCreator with G

阅读更多
有时候我们在使用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://stackoverflow.com/questions/3294829/java-reading-json-null
1
2
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics