Java:ArrayList 上的 StringUtils.join 返回 NoSuchMethodError 异常
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3406863/
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
Java: StringUtils.join on an ArrayList returns NoSuchMethodError Exception
提问by ufk
I have an ArrayList that i would like to join with a delimiter of ',', i read in some answers here that StringUtils.join is a good option but the problem is that when i try to join an ArrayList i get the following error:
我有一个 ArrayList,我想用 ',' 分隔符加入它,我在这里读到一些答案,StringUtils.join 是一个不错的选择,但问题是当我尝试加入一个 ArrayList 时,出现以下错误:
java.lang.NoSuchMethodError: org.apache.commons.lang.StringUtils.join(Ljava/util/Collection;C)Ljava/lang/String;
code:
代码:
ArrayList<String> friendsList = new ArrayList<String>();
.
.
.
StringUtils.join(friendsList, ',');
what am i missing ?
我错过了什么?
when i'm coding with netbeans it does not alert me of this error, it happens only when I try to compile.
当我用 netbeans 编码时,它不会提醒我这个错误,它只在我尝试编译时发生。
采纳答案by Bozho
You have an older version of commons-lang. Get the latest version, which has this method.
你有一个旧版本的 commons-lang。获取具有此方法的最新版本。
Alternatively, you can call StringUtils.join(friendsList.toArray(), ',')
或者,您可以致电 StringUtils.join(friendsList.toArray(), ',')
回答by Eyal Schneider
"it happens only when I try to compile."
“只有在我尝试编译时才会发生。”
This is not a compilation error. It's a linkage error that happens at runtime when the signature of the method being invoked does not match the one of the relevant class in the classpath. You probably have different jars at compile time and runtime (different versions maybe).
这不是编译错误。当被调用的方法的签名与类路径中的相关类之一不匹配时,这是在运行时发生的链接错误。您可能在编译时和运行时有不同的 jar(可能版本不同)。
回答by Zaki
An issue with classpath I guess.
我猜是类路径的问题。
回答by Antoine
This method exists since commons lang 2.3, check your jar.
此方法自 commons lang 2.3 以来就存在,请检查您的 jar。
回答by Amara
I use 2.4.jar. Still I had to use something like this StringUtils.join(friendsList.toArray(), ',') to get it done.
我使用 2.4.jar。我仍然必须使用类似 StringUtils.join(friendsList.toArray(), ',') 的东西来完成它。