这是我的代码。我添加了所有依赖项,然后也收到了此类错误。
google-http-client-jackson2-1.17.0-rc.jar
在此代码中获得上述错误时,在JsonFactory jsonFactory = new JacksonFactory();
import com.google.api.services.customsearch.Customsearch;
import com.google.api.services.customsearch.model.Search;
import com.google.api.services.customsearch.model.Result;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.HttpRequest;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
protected SearchResult[] doSearch() {
HttpRequestInitializer httpRequestInitializer = new HttpRequestInitializer()
{
@Override
public void initialize(HttpRequest request) throws IOException {
}
};
JsonFactory jsonFactory = new JacksonFactory();
Customsearch csearch = new Customsearch( new NetHttpTransport(), jsonFactory, httpRequestInitializer);
Customsearch.Cse.List listReqst;
try {
listReqst = csearch.cse().list(query.getQueryString());
listReqst.setKey(GOOGLE_KEY);
// set the search engine ID got from API console
listReqst.setCx("search engine ID");
// set the query string
listReqst.setQ(query.getQueryString());
// language chosen is English for search results
listReqst.setLr("lang_en");
// set hit position of first search result
listReqst.setStart((long) firstResult);
// set max number of search results to return
listReqst.setNum((long) maxResults);
//performs search
Search result = listReqst.execute();
java.util.List<Result> results = result.getItems();
String urls[] = new String [result.size()];
String snippets[] = new String [result.size()];
int i=0;
for (Result r : results){
urls[i] = r.getLink();
snippets[i] = r.getSnippet();
i++;
}
return getResults(snippets, urls, true);
} catch (IOException e) {
// TODO Auto-generated catch block
MsgPrinter.printSearchError(e);
System.exit(1);
return null;
}
}
请建议我该如何解决。
最佳答案
直接回答问题(在Pavel的评论中得到回答)。杰克逊核心库依赖项缺失:
jackson-core- $ x.y.z.jar