【求助】Kotlin使用hutool工具类库时,一调用Util就抛出java.lang.reflect.InvocationTargetException该如何解决?
-
控制台日志:
2022-07-27 12:41:40 E/console: java.lang.reflect.InvocationTargetException java.lang.reflect.InvocationTargetException at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:564) at kotlin.reflect.jvm.internal.calls.CallerImpl$Method.callMethod(CallerImpl.kt:97) at kotlin.reflect.jvm.internal.calls.CallerImpl$Method$Instance.call(CallerImpl.kt:113) at kotlin.reflect.jvm.internal.KCallableImpl.call(KCallableImpl.kt:108) at kotlin.reflect.jvm.internal.KCallableImpl.callDefaultMethod$kotlin_reflection(KCallableImpl.kt:159) at kotlin.reflect.full.KCallables.callSuspendBy(KCallables.kt:74) at net.mamoe.mirai.console.internal.command.CommandReflector$findSubCommands$6$1.invokeSuspend(CommandReflector.kt:329) at net.mamoe.mirai.console.internal.command.CommandReflector$findSubCommands$6$1.invoke(CommandReflector.kt) at net.mamoe.mirai.console.internal.command.CommandReflector$findSubCommands$6$1.invoke(CommandReflector.kt) at net.mamoe.mirai.console.command.descriptor.CommandSignatureFromKFunctionImpl.call$suspendImpl(CommandSignature.kt:88) at net.mamoe.mirai.console.command.descriptor.CommandSignatureFromKFunctionImpl.call(CommandSignature.kt) at net.mamoe.mirai.console.internal.command.CommandManagerImplKt.executeCommandImpl(CommandManagerImpl.kt:168) at net.mamoe.mirai.console.command.CommandManager.executeCommand$suspendImpl(CommandManager.kt:130) at net.mamoe.mirai.console.command.CommandManager.executeCommand(CommandManager.kt) at net.mamoe.mirai.console.command.CommandManager$INSTANCE.executeCommand(CommandManager.kt) at net.mamoe.mirai.console.terminal.ConsoleThreadKt$startupConsoleThread$3.invokeSuspend(ConsoleThread.kt:191) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106) at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:749) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664) Caused by: java.lang.NoClassDefFoundError: cn/hutool/http/HttpUtil at org.ASN70.apiExercise.Commands$COVID19.handle(Commands.kt:14) ... 25 more Caused by: java.lang.ClassNotFoundException: cn.hutool.http.HttpUtil at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:606) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:168) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522) ... 26 more
调用HttpUtil.get时的代码
suspend fun CommandSender.handle() { val jsonData = HttpUtil.get("https://www.baidu.com") println(jsonData) }
-
请检查你的打包是否有问题