---
title: "No-args constructor for class does not exist. Register an InstanceCreator with G"
author: "JavaEEdyc"
date: "2013-06-26T17:16:09Z"
tags: []
categories: ["移动开发"]
slug: "no-args-constructor-for-class-does-not-exist-register-an-instancecreator-with-g"
draft: false
lastmod: "2015-04-22T12:58:30Z"
id: 1894799
url: "https://javaeedyc.iteye.com/blog/1894799"
---

有时候我们在使用Googel官方的json解析包时，如果自己的实体类中出现代参的构造函数，如；


```java

[*]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;
[*]    }

```

如果这样写的话，有时候会报这样的错误；

<span style="color:red">**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)**</span>
简单认识就是我们自己写了构造函数后，本身自带的无参就会忽略，但是json.jar包中的Gson，需要！简单方法就是加上无参数构造函数!




参考：
<http://stackoverflow.com/questions/3294829/java-reading-json-null>