Gson serialized name: “Implicit super constructor Object() is undefined for default constructor. Must define an explicit constructor”

大憨熊 提交于 2020-01-06 18:07:42

问题


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

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?

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

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;

}

Thanks in advance.


回答1:


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).

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

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



来源:https://stackoverflow.com/questions/14466323/gson-serialized-name-implicit-super-constructor-object-is-undefined-for-defa

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!