使用com.google.common.base.Splitter时出现NoSuchMethodError异常

问题描述:

我正在尝试使用com.google.common.base.Splitter,如下所示

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?

我遇到了同样的问题。
结果我使用了旧版番石榴。
访问该网站: https://code.google.com/p/guava -libraries / ,并下载更新的版本。

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.

顺便说一下,google-collections被重命名为Guava。

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