GSON系列化名称:"隐超级构造函数对象()是未定义默认构造函数。必须定义一个明确的构造函数和QUOT; [英] Gson serialized name: "Implicit super constructor Object() is undefined for default constructor. Must define an explicit constructor"

查看:543
本文介绍了GSON系列化名称:"隐超级构造函数对象()是未定义默认构造函数。必须定义一个明确的构造函数和QUOT;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的Andr​​oid,和我想学习如何使用GSON解析API调用。我读过周围一点点,我试图以此为榜样:的 HTTP://www.java$c$cgeeks.com/2011/01/android-json-parsing-gson-tutorial.html

I'm new to Android, and I'm trying to learn how to use Gson to parse an API call. I've read around a little bit, and I'm trying to follow this example: http://www.javacodegeeks.com/2011/01/android-json-parsing-gson-tutorial.html

这是怎么回事相对较好,但是当我导入项目到Eclipse获得在code更好看,我遇到了上述关于构造错误(以及其他一些令人困惑的错误)。

It's going relatively well, but when I imported the project into Eclipse to get a better look at the code, I encountered the error above regarding constructors (as well as a few other confusing errors).

我在这里读了一些相关问题上的计算器,但它们都涉及继承的类,并且,我可能会非常困惑,但我没想到这个类是继承的。

I read some related questions here on StackOverflow, but they all involve inherited classes, and, I may be terribly confused, but I didn't think this class was inherited.

是什么导致这些错误,以及如何解决这些问题?

What is causing these errors, and how can I fix them?

如果你想有一个链接的项目,而不通过挖掘文章,它可在这里:<一href=\"http://dl.dropbox.com/u/7215751/Java$c$cGeeks/AndroidJsonParsingTutorial/AndroidJsonProject.zip\" rel=\"nofollow\">http://dl.dropbox.com/u/7215751/Java$c$cGeeks/AndroidJsonParsingTutorial/AndroidJsonProject.zip

If you want a link the the project without digging through the article, it's available here: http://dl.dropbox.com/u/7215751/JavaCodeGeeks/AndroidJsonParsingTutorial/AndroidJsonProject.zip

下面是有问题的文件中的code:
包com.java codegeeks.android.json.model;

Here is the code from the file in question: package com.javacodegeeks.android.json.model;

import com.google.gson.annotations.SerializedName;

public class SearchResponse {

public List<Result> results;

@SerializedName("max_id")
public long maxId;

@SerializedName("since_id")
public int sinceId;

@SerializedName("refresh_url")
public String refreshUrl;

@SerializedName("next_page")
public String nextPage;

@SerializedName("results_per_page")
public int resultsPerPage;

public int page;

@SerializedName("completed_in")
public double completedIn;

@SerializedName("since_id_str")
public String sinceIdStr;

@SerializedName("max_id_str")
public String maxIdStr;

public String query;

}

先谢谢了。

推荐答案

您的研究是正确的 - 提到的错误与构造函数和继承。
如此看来,在某处你的项目,你有一个Employee类,而该类未声明的公共(或至少保护)空构造(即一个构造函数没有参数)。

Your research is correct - the mentioned error is related to constructors and inheritance. It seems that somewhere in your project, you have an Employee class, and that class does not declare a public (or at least protected) null constructor (i.e. a constructor that takes no parameters).

在所提供的示例code我找不到这样一类的任何提及 - 也许是你加入到实验

In the provided sample code I could not find any mention of such a class - perhaps something you added to experiment with?

任何情况下,添加一个空的构造所提到的Employee类应该让你的一些问题消失。

Any case, adding a null constructor to the mentioned Employee class should make some of your problems go away.

这篇关于GSON系列化名称:&QUOT;隐超级构造函数对象()是未定义默认构造函数。必须定义一个明确的构造函数和QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆