Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NoSuchMethodError exception when using com.google.common.base.Splitter

Tags:

I'm trying to use com.google.common.base.Splitter as follows

Iterable<String> segs = Splitter.on("/").split("one/two/three/four/five");  for (String seg : segs) {   System.out.println(seg); } 

However, I'm seeing the following exception:

Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.base.Platform.precomputeCharMatcher(Lcom/google/common/base/CharMatcher;)Lcom/google/common/base/CharMatcher;     at com.google.common.base.CharMatcher.precomputed(CharMatcher.java:664)     at com.google.common.base.CharMatcher.<clinit>(CharMatcher.java:71)     at com.google.common.base.Splitter.<init>(Splitter.java:107)     at com.google.common.base.Splitter.on(Splitter.java:171)     at Test.main(Test.java:30) 

Does anyone have any idea what I'm doing wrong here?

like image 511
mip Avatar asked Nov 24 '11 13:11

mip


Video Answer


2 Answers

I encountered the same problem. It turned out that I used a older version of guava. Go to this website:https://code.google.com/p/guava-libraries/, and download a newer version.

By the way,google-collections was renamed to Guava.

like image 107
Sam003 Avatar answered Oct 25 '22 15:10

Sam003


Use the below dependency to fix the issue

To add a dependency on Guava using Maven, use the following:

<dependency>   <groupId>com.google.guava</groupId>   <artifactId>guava</artifactId>   <version>19.0</version> </dependency> 

To add a dependency using Gradle:

dependencies {   compile 'com.google.guava:guava:19.0' } 
like image 38
Indrajeet Gour Avatar answered Oct 25 '22 13:10

Indrajeet Gour