Splitter 在简单的 Pattern 上爆炸
我刚刚开始使用 Guava 代替 Google-Collections。 Splitter 类看起来很酷。但是当我使用它时,就像这样:
private static final Pattern p = Pattern.compile(" +");
private static final Splitter usSplitter = Splitter.on(p).trimResults();
我得到一个堆栈转储:
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:662)
at com.google.common.base.CharMatcher.<clinit>(CharMatcher.java:69)
at com.google.common.base.Splitter.<init>(Splitter.java:99)
at com.google.common.base.Splitter.on(Splitter.java:208)
javadoc 没有关于这个“com.google.common.base.Platform”的信息。所以很难猜测出了什么问题。
正如您所看到的,该模式非常简单。
I am just starting to us Guava in place of Google-Collections. The Splitter class seemed cool. But when I use it, like this:
private static final Pattern p = Pattern.compile(" +");
private static final Splitter usSplitter = Splitter.on(p).trimResults();
I get a stack dump:
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:662)
at com.google.common.base.CharMatcher.<clinit>(CharMatcher.java:69)
at com.google.common.base.Splitter.<init>(Splitter.java:99)
at com.google.common.base.Splitter.on(Splitter.java:208)
The javadocs have nothing about this "com.google.common.base.Platform." so its a bit hard to guess what is going wrong.
As you can see, the Pattern is dead simple.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
java.lang.NoSuchMethodError
告诉您当前运行时类路径中缺少所需的方法,而该方法却存在于编译时类路径中。换句话说,要解决此问题,您需要调整运行时类路径,以获得编译时使用的正确版本的 API。它还可能是由于在运行时类路径中混合了不同版本的库而引起的。然后清理类路径。
The
java.lang.NoSuchMethodError
tells you that the desired method is missing in the current runtime classpath while it was there in the compile time classpath.In other words, to fix this problem you need to align your runtime classpath to have the correct version of the API as you used during compile time. It can also be caused by having different versions of the library mixed throughout the runtime classpath. Cleanup the classpath then.
您使用什么版本的番石榴?这对于我的 r05 来说效果非常好。
编辑:这里的具体问题似乎是您的运行时类路径中同时有 google-collections 和 guava 。
Platform
(内部类)存在于 google-collections 中,但没有precompulatedCharMatcher
方法。Splitter
正在从 guava jar 正确加载,但Platform
正在从 google-collect jar 加载。What version of Guava are you using? This works perfectly fine for me with r05.
Edit: It seems like the specific issue here is that you have both google-collections and guava in your runtime classpath.
Platform
(an internal class) existed in google-collections but didn't have theprecomputedCharMatcher
method.Splitter
is being loaded from the guava jar properly, butPlatform
is being loaded from the google-collect jar.实际上。您有两个版本的
com.google.common.base.Platform
类,其中一个类具有或不具有该方法。尝试删除其中一个 jar 文件。我建议删除
google-collections.jar
并保留gauva.jar
。它会工作得很好。
Actually. you got two version of
com.google.common.base.Platform
class and one of these classes has or hasn't the method.Try to remove one of the jar files. I suggest to remove
google-collections.jar
and leavegauva.jar
.It will work fine.