我想在我的应用程序中使用Guice,但是当我想运行它时会抛出异常:
Exception in thread "main"
Exception: com.google.common.util.concurrent.UncheckedExecutionException thrown from the UncaughtExceptionHandler in thread "main"
当我用try ... catch块包装main()
函数时,我会收到folloving 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定义的方法引起的,是由Provide方法引发的。不过它应该用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
}
}
答案 0 :(得分:0)
我使用Java 10,但也尝试了8和9.没有任何帮助。
我认为您没有使用Java 8或9,因为使用Java 10或更高版本会导致ClassReader
引发异常。
Opcodes.V9
表示Java 9.所以请再次检查Java版本并使用Java 9或更早版本运行。