gpt4 book ai didi

java - Guice 导致抛出 UncaughtExceptionHandler

转载 作者:行者123 更新时间:2023-12-02 11:09:38 30 4
gpt4 key购买 nike

我想在我的应用程序中使用 Guice,但当我想运行它时它会抛出以下异常:

Exception in thread "main" 
Exception: com.google.common.util.concurrent.UncheckedExecutionException thrown from the UncaughtExceptionHandler in thread "main"

当我用 try...catch block 包装 main() 函数时,我收到以下 stackTrace:

Exception in thread "main" com.google.common.util.concurrent.UncheckedExecutionException: java.lang.IllegalArgumentException
at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2047)
at com.google.common.cache.LocalCache.get(LocalCache.java:3869)
at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:3873)
at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4798)
at com.google.common.cache.LocalCache$LocalLoadingCache.getUnchecked(LocalCache.java:4804)
at com.google.inject.internal.util.StackTraceElements.forMember(StackTraceElements.java:71)
at com.google.inject.internal.Messages.formatSource(Messages.java:241)
at com.google.inject.internal.Messages.formatSource(Messages.java:220)
at com.google.inject.internal.Messages.formatMessages(Messages.java:90)
at com.google.inject.CreationException.getMessage(CreationException.java:50)
at java.base/java.lang.Throwable.getLocalizedMessage(Throwable.java:396)
at java.base/java.lang.Throwable.toString(Throwable.java:485)
at java.base/java.lang.String.valueOf(String.java:2788)
at java.base/java.io.PrintStream.println(PrintStream.java:897)
at java.base/java.lang.Throwable$WrappedPrintStream.println(Throwable.java:752)
at java.base/java.lang.Throwable.printStackTrace(Throwable.java:659)
at java.base/java.lang.Throwable.printStackTrace(Throwable.java:648)
at java.base/java.lang.Throwable.printStackTrace(Throwable.java:639)
at com.github.blackjack.Main.main(Main.java:31)
Caused by: java.lang.IllegalArgumentException
at com.google.inject.internal.asm.$ClassReader.<init>(ClassReader.java:160)
at com.google.inject.internal.asm.$ClassReader.<init>(ClassReader.java:143)
at com.google.inject.internal.asm.$ClassReader.<init>(ClassReader.java:418)
at com.google.inject.internal.util.LineNumbers.<init>(LineNumbers.java:64)
at com.google.inject.internal.util.StackTraceElements$1.load(StackTraceElements.java:49)
at com.google.inject.internal.util.StackTraceElements$1.load(StackTraceElements.java:45)
at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3443)
at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2169)
at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2128)
at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2041)
... 18 more

从信息中我发现这个异常是由包含lambda定义的方法引起的,是由Provides方法抛出的。尽管如此,它应该用 Guice 4.0 修复。也许有人知道如何解决它并可以提供帮助?提前致谢!

main()函数:

public static void main (String[] args){
try{
MainModule module = new MainModule();
Injector injector = Guice.createInjector(module);

GameFactory gameFactory = injector.getInstance(GameFactory.class);
DeckFactory blackjackDeckFactory = injector.getInstance(BlackjackDeckCreator.class);
PlayerFactory playerFactory = injector.getInstance(PlayerFactory.class);

Player player = playerFactory.createPlayer("Paul");
Player dealer = playerFactory.createPlayer("Dealer", true);

Deck deck = blackjackDeckFactory.createDeck();

Game game = gameFactory.createGame(player, dealer, deck);
game.start();
} catch (Exception e){
e.printStackTrace(); // line 31
}
}

最佳答案

I use Java 10, but also tried 8 and 9. Nothing helped.

我认为您没有使用 Java 8 或 9,因为由于使用 Java 版本 10 或更高版本,ClassReader 引发了异常。

https://gitlab.ow2.org/asm/asm/blob/f7f44a8e306dd2bd70f0db50194f6366938579c5/src/org/objectweb/asm/ClassReader.java#L160

Opcodes.V9 表示 Java 9。因此,请再次检查您的 Java 版本并使用 Java 9 或更早版本运行。

关于java - Guice 导致抛出 UncaughtExceptionHandler,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50693221/

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