Java:ArrayList 上的 StringUtils.join 返回 NoSuchMethodError 异常
我有一个 ArrayList,我想用 ',' 分隔符连接, 我在这里读到一些答案,认为 StringUtils.join 是一个不错的选择,但问题是,当我尝试加入 ArrayList 时,出现以下错误:
java.lang.NoSuchMethodError: org.apache.commons.lang.StringUtils.join(Ljava/util/Collection;C)Ljava/lang/String;
代码:
ArrayList<String> friendsList = new ArrayList<String>();
.
.
.
StringUtils.join(friendsList, ',');
我缺少什么?
当我使用 netbeans 进行编码时,它不会提醒我此错误,它仅在我尝试编译时发生。
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:
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您有旧版本的 commons-lang。获取最新版本,有这个方法。
或者,您可以调用 StringUtils.join(friendsList.toArray(), ',')
You have an older version of commons-lang. Get the latest version, which has this method.
Alternatively, you can call
StringUtils.join(friendsList.toArray(), ',')
“只有当我尝试编译时才会发生这种情况。”
这不是编译错误。当被调用的方法的签名与类路径中的相关类的签名不匹配时,这是在运行时发生的链接错误。您可能在编译时和运行时有不同的 jar(可能是不同的版本)。
"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).
我猜是类路径的问题。
An issue with classpath I guess.
这个方法从commons lang 2.3开始就存在,检查你的jar。
This method exists since commons lang 2.3, check your jar.
我用的是2.4.jar。我仍然必须使用类似 StringUtils.join(friendsList.toArray(), ',') 的东西来完成它。
I use 2.4.jar. Still I had to use something like this StringUtils.join(friendsList.toArray(), ',') to get it done.