playframework: WSRequestHolder holder = WS.url(url) -> error: no suitable method found for url(String)
playframework: WSRequestHolder holder = WS.url(url) -> error: no suitable method found for url(String)
我在尝试在我的应用程序中保存一些数据时遇到问题。我的代码的相关部分是:
String url = "http://xxx.xxx.x.xxx:xxxx/en";
HashMap<Integer,String> id_name_env = new HashMap<Integer,String>();
WSRequestHolder holder = WS.url(url); //here is the problem ...
holder.setHeader("Cookie", "sessionid="+ session("sessionid"));
holder.setContentType("application/json");
ArrayList<Integer> envList = new ArrayList<Integer>();
WSResponse response = holder.get().get(20000);
JsonNode content = response.asJson();
List<String> listaIduri = content.findValuesAsText("id");
for( String id : listaIduri){
id_name_env.put(Integer.parseInt(id), id);
}
我得到的错误是:
error: no suitable method found for url(String)
在 Eclipse 中,它给出不同的消息:
The method url(WSRequestHolderMagnet) in the type WS is not applicable for the arguments (String)
我做错了什么? url
有问题吗? Eclipse 建议将 url
变量类型更改为 WSRequestHolderMagnet
.
可能您正在导入 play.api.libs.ws.WS
并且仅供 Scala 使用。通常,您可以假设 play.api.x.y.z
中的某些内容将在 Scala 中使用,并且它可能有一个 play.x.y.z
将在 Java.
中使用
尝试导入 play.libs.ws.WS
。
我在从 play 2.2 迁移到 play 2.3 时遇到了这个问题,我解决了它,将 JavaWS 依赖项添加到 build.sbt 并将行 "import play.api.libs.ws." 替换为 "import play.libs.ws."。
您还可以阅读 Play 2.3 迁移指南。
我在尝试在我的应用程序中保存一些数据时遇到问题。我的代码的相关部分是:
String url = "http://xxx.xxx.x.xxx:xxxx/en";
HashMap<Integer,String> id_name_env = new HashMap<Integer,String>();
WSRequestHolder holder = WS.url(url); //here is the problem ...
holder.setHeader("Cookie", "sessionid="+ session("sessionid"));
holder.setContentType("application/json");
ArrayList<Integer> envList = new ArrayList<Integer>();
WSResponse response = holder.get().get(20000);
JsonNode content = response.asJson();
List<String> listaIduri = content.findValuesAsText("id");
for( String id : listaIduri){
id_name_env.put(Integer.parseInt(id), id);
}
我得到的错误是:
error: no suitable method found for url(String)
在 Eclipse 中,它给出不同的消息:
The method url(WSRequestHolderMagnet) in the type WS is not applicable for the arguments (String)
我做错了什么? url
有问题吗? Eclipse 建议将 url
变量类型更改为 WSRequestHolderMagnet
.
可能您正在导入 play.api.libs.ws.WS
并且仅供 Scala 使用。通常,您可以假设 play.api.x.y.z
中的某些内容将在 Scala 中使用,并且它可能有一个 play.x.y.z
将在 Java.
尝试导入 play.libs.ws.WS
。
我在从 play 2.2 迁移到 play 2.3 时遇到了这个问题,我解决了它,将 JavaWS 依赖项添加到 build.sbt 并将行 "import play.api.libs.ws." 替换为 "import play.libs.ws."。
您还可以阅读 Play 2.3 迁移指南。