java Apache StringUtils 中的异常

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9915324/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 22:53:05  来源:igfitidea点击:

Exception in Apache StringUtils

javastringjspapache-stringutils

提问by King Aslan

hello guys i am try to use the StringUtils.remove Method but the below exception is raising i have include the jar file and StringUtils.lowercase and String.countsMatches is working only remove is not what may be the problem

大家好,我正在尝试使用 StringUtils.remove 方法,但出现以下异常,我已包含 jar 文件和 StringUtils.lowercase 和 String.countsMatches 正在工作,但仅删除不是问题所在

<%@page import="org.apache.commons.lang.StringUtils"%>

this is how i imported and the exception is as follows

这就是我导入的方式,异常如下

java.lang.NoSuchMethodError:
org.apache.commons.lang.StringUtils.remove(Ljava/lang/String;Ljava/lang/String;)
Ljava/lang/String;

回答by Christian Semrau

The remove(String,String)method was added to version 2.1 of commons-lang. It is not present in 2.0 and earlier.

remove(String,String)方法已添加到 commons-lang 2.1 版中。它在 2.0 及更早版本中不存在。

Depending on which Servlet Container or Application Server you use (and which version of it), the server class path may contain an outdated version of commons-lang, which is used instead of your copy of commons-lang in the applications /lib folder. If that's your problem, you can configure your application to prefer the application class path, instead of the server class path.

根据您使用的 Servlet 容器或应用程序服务器(以及它的哪个版本),服务器类路径可能包含一个过时的 commons-lang 版本,它用于代替您在应用程序 /lib 文件夹中的 commons-lang 副本。如果这是您的问题,您可以将应用程序配置为更喜欢应用程序类路径,而不是服务器类路径。

回答by AlexR

Because as far as I can see in javadoc StringUtils has method remove that accepts 2 string arguments and does not have one that accepts 3 arguments:

因为据我在 javadoc StringUtils 中看到的方法 remove 接受 2 个字符串参数并且没有接受 3 个参数的方法:

public static String remove(String str,
                            String remove)

see http://commons.apache.org/lang/api-2.5/org/apache/commons/lang/StringUtils.html

http://commons.apache.org/lang/api-2.5/org/apache/commons/lang/StringUtils.html

Since there are different versions of StringUtils double check that your are working with the same version in development and deployment environment.

由于有不同版本的 StringUtils,请仔细检查您在开发和部署环境中是否使用相同的版本。