gpt4 book ai didi

java - 类型 "x"中的方法 search() 不适用于参数(字符串)

转载 作者:行者123 更新时间:2023-12-01 15:19:42 25 4
gpt4 key购买 nike

设置 Mac OSX 10.6.7、Eclipse、Tomcat 1.6

我试图将 Java 文件中的字符串调用到 JSP 以将其显示给用户,但我不断收到以下错误。一如既往,我们非常感谢任何帮助,

JSP

<%
Injector injector = Guice.createInjector(new GuiceInjector());
SliceConnector r = injector.getInstance(SliceConnector.class);
out.println(r.search());

String dbConcept = "http://dbpedia.org/resource/human_rights";
System.out.println(r.search(dbConcept));
%>

Java

public String search(String dbConcept)
{
setSlicepediaProductionMode(true);

List<SliceHit> sliceHits = searchForSlices();
if (sliceHits == null) {
System.err.println("Timeout occurred while fetching slices");
return "error";
}
if (!sliceHits.isEmpty()) {
System.out.println("Found some slices Yuhuuuu ! :-) ");
String sliceContent = createSlices(sliceHits);
System.out.println("Slice content:");
System.out.println(sliceContent);
return sliceContent;
} else {
System.out.println("No Slices were found for this query");
}
System.out.println("Slice Consumer stopped activity");
return "SliceConnector";
}

private void setSlicepediaProductionMode(boolean productionMode)
{
sliceSearcher.setProductionMode(productionMode);
sliceCreator.setProductionMode(productionMode);
}
private List<SliceHit> searchForSlices() {
SlicepediaQuery sliceQuery = new SlicepediaQuery();

String dbConcept = "http://dbpedia.org/resource/human_rights";

sliceSearcher.setSliceQuery(sliceQuery);
if (sliceSearcher.run())
{
return sliceSearcher.getSliceHits();
} else
{
return null;
}
}

错误

exception

org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: 141 in the jsp file: /SimpleResponse2.jsp
The method search() in the type SliceConnector is not applicable for the arguments (String)
138:
139:
140: String dbConcept = "http://dbpedia.org/resource/human_rights";
141: System.out.println(r.search(dbConcept));

最佳答案

我看到您调用 search() 两次,第一次不带参数,第二次使用字符串。在发布的代码中,您只提供了后一种情况,因此您应该在第一次调用时就已经收到错误。

更正第一个调用并确保引用正确的文件。

关于java - 类型 "x"中的方法 search() 不适用于参数(字符串),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11126977/

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