gpt4 book ai didi

java.lang.NoClassDefFoundError : com/fasterxml/jackson/core/JsonFactory getting this error even after adding the desired imports

转载 作者:行者123 更新时间:2023-11-30 03:57:28 25 4
gpt4 key购买 nike

这是我的代码。我已经添加了所有依赖项,然后也收到这样的错误。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 核心库依赖项丢失:jackson-core-$x.y.z.jar

关于java.lang.NoClassDefFoundError : com/fasterxml/jackson/core/JsonFactory getting this error even after adding the desired imports,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22819511/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com