Splitter 在简单的 Pattern 上爆炸

发布于 2024-09-07 08:20:50 字数 831 浏览 5 评论 0原文

我刚刚开始使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

淡莣 2024-09-14 08:20:50

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.

舂唻埖巳落 2024-09-14 08:20:50

您使用什么版本的番石榴?这对于我的 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 the precomputedCharMatcher method. Splitter is being loaded from the guava jar properly, but Platform is being loaded from the google-collect jar.

深巷少女 2024-09-14 08:20:50

实际上。您有两个版本的 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 leave gauva.jar.

It will work fine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文