问题
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