Java:ArrayList 上的 StringUtils.join 返回 NoSuchMethodError 异常

发布于 2024-09-13 01:21:18 字数 462 浏览 1 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

马蹄踏│碎落叶 2024-09-20 01:21:18

您有旧版本的 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(), ',')

鸵鸟症 2024-09-20 01:21:18

“只有当我尝试编译时才会发生这种情况。”

这不是编译错误。当被调用的方法的签名与类路径中的相关类的签名不匹配时,这是在运行时发生的链接错误。您可能在编译时和运行时有不同的 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).

千秋岁 2024-09-20 01:21:18

我猜是类路径的问题。

An issue with classpath I guess.

莫多说 2024-09-20 01:21:18

这个方法从commons lang 2.3开始就存在,检查你的jar。

This method exists since commons lang 2.3, check your jar.

夜司空 2024-09-20 01:21:18

我用的是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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文