views:

110

answers:

4

Hello.

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.

+1  A: 

"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).

Eyal Schneider
+1  A: 

An issue with classpath I guess.

Zaki
+3  A: 

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

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

Bozho
+1  A: 

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

Antoine