Java: StringUtils.join on ArrayList returns NoSuchMethodError exception

I have an ArrayList that I would like to combine with the separator ',', I read in some answers that StringUtils.join is a good option, but the problem is that when I try to join the ArrayList, I get the following error:

java.lang.NoSuchMethodError: org.apache.commons.lang.StringUtils.join(Ljava/util/Collection;C)Ljava/lang/String; 

the code:

 ArrayList<String> friendsList = new ArrayList<String>(); . . . StringUtils.join(friendsList, ','); 

What am I missing?

when I encode netbeans, it does not warn me about this error, it only happens when trying to compile.

+7
java arraylist apache-commons
source share
5 answers

You have an older version of commons-lang. Get the latest version that has this method.

Alternatively, you can call StringUtils.join(friendsList.toArray(), ',')

+19
source share

"this only happens when I try to compile."

This is not a compilation error. This is a communication error that occurs at runtime when the signature of the called method does not match one of the corresponding class in the classpath. You probably have different banks at compile time and runtime (possibly different versions).

+2
source share

Problem with classpath, I think.

+1
source share

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

+1
source share

I am using 2.4.jar. However, I had to use something like this StringUtils.join (friendsList.toArray (), ',') to do this.

+1
source share

All Articles