gpt4 book ai didi

java - 创建 Abdera 客户端失败

转载 作者:搜寻专家 更新时间:2023-10-31 20:28:32 26 4
gpt4 key购买 nike

创建 apache Abdera 客户端失败

我的部分代码是

    Abdera abdera = new Abdera();
AbderaClient abderaClient = new AbderaClient(abdera);

这让我很震惊......

java.lang.RuntimeException: java.lang.NoSuchMethodException: org.apache.abdera.protocol.client.cache.LRUCacheFactory.<init>(org.apache.abdera.Abdera)
at org.apache.abdera.util.Discover.locate(Discover.java:37)
at org.apache.abdera.util.Discover.locate(Discover.java:21)
at org.apache.abdera.util.ServiceUtil.newInstance(ServiceUtil.java:142)
at org.apache.abdera.protocol.client.AbderaClient.initCacheFactory(AbderaClient.java:132)
at org.apache.abdera.protocol.client.AbderaClient.<init>(AbderaClient.java:108)
at org.apache.abdera.protocol.client.AbderaClient.<init>(AbderaClient.java:9
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.rules.ExpectedException$ExpectedExceptionStatement.evaluate(ExpectedException.java:168)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:65)
Caused by: java.lang.NoSuchMethodException: org.apache.abdera.protocol.client.cache.LRUCacheFactory.<init>(org.apache.abdera.Abdera)
at java.lang.Class.getConstructor0(Class.java:2706)
at java.lang.Class.getConstructor(Class.java:1657)
at org.apache.abdera.util.Discover.load(Discover.java:149)
at org.apache.abdera.util.Discover.locate(Discover.java:33)
... 30 more

任何帮助!!

最佳答案

显然看起来像是 AbderaClient 的以下方法中的错误;它使用反射来定位 LRUCacheFactory 的构造函数:

   private CacheFactory initCacheFactory() {
CacheFactory cacheFactory =
(CacheFactory)Discover.locate(
CacheFactory.class.getName(),
LRUCacheFactory.class.getName(),
abdera);
return cacheFactory;
}

检查你的LRUCacheFactory版本中是否有这样的构造函数。

建议切换到最新的 Abdera 版本 (1.1.3)。但是,我在论坛中也找到了解决方法。试试它是否有效。

AbderaClient client;
ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
try {
ClassLoader cl = this.getClass().getClassLoader();
Thread.currentThread().setContextClassLoader(cl);

Abdera abdera = new Abdera();
client = new AbderaClient(abdera);

// Do something with client

} finally {
// Restore original classloader
Thread.currentThread().setContextClassLoader(originalClassLoader);
}

引用this link有关此解决方法的更多详细信息。

关于java - 创建 Abdera 客户端失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21904319/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com