При попытке запустить код Телеграм бота на Java появляютя ошибки
Смотрите у меня есть два файла:
Main.java
package org.example;
public class Main {
public static void main(String[] args) {
bOT bot = new bOT("BOT_TOKEN", "BOT_NICK");
}
}
и bOT.java
package org.example;
import org.telegram.telegrambots.api.methods.ParseMode;
import org.telegram.telegrambots.api.methods.send.SendMessage;
import org.telegram.telegrambots.api.objects.Update;
import org.telegram.telegrambots.bots.TelegramLongPollingBot;
import org.telegram.telegrambots.exceptions.TelegramApiException;
public class bOT extends TelegramLongPollingBot {
private String botToken;
private String botName;
public bOT(String botToken, String botName) {
this.botToken = botToken;
this.botName = botName;
}
@Override
public void onUpdateReceived(Update update) {
if (update.hasMessage() && update.getMessage().hasText()) {
String msg_from_usr = update.getMessage().getText();
long chatId = update.getMessage().getChatId();
SendMessage msg_from_bot = new SendMessage();
msg_from_bot.setChatId(String.valueOf(chatId));
if (msg_from_usr.equals("/start".toLowerCase())) {
msg_from_bot.setParseMode(ParseMode.HTML);
msg_from_bot.setText("<b>Привет!</b>");
try {
execute(msg_from_bot); // Отправляем сообщение
} catch (TelegramApiException e) {
e.printStackTrace();
}
}
}
}
@Override
public String getBotToken() {
return botToken;
}
@Override
public String getBotUsername() {
return botName;
}
}
Когда я запускаю у меня появлются такие ошибки:
Exception in thread "main" com.google.common.util.concurrent.ExecutionError: java.lang.ExceptionInInitializerError
at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2205)
at com.google.common.cache.LocalCache.get(LocalCache.java:3953)
at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:3957)
at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4875)
at com.google.common.cache.LocalCache$LocalLoadingCache.getUnchecked(LocalCache.java:4881)
at com.google.inject.internal.FailableCache.get(FailableCache.java:48)
at com.google.inject.internal.ConstructorInjectorStore.get(ConstructorInjectorStore.java:50)
at com.google.inject.internal.ConstructorBindingImpl.initialize(ConstructorBindingImpl.java:138)
at com.google.inject.internal.InjectorImpl.initializeJitBinding(InjectorImpl.java:550)
at com.google.inject.internal.InjectorImpl.createJustInTimeBinding(InjectorImpl.java:887)
at com.google.inject.internal.InjectorImpl.createJustInTimeBindingRecursive(InjectorImpl.java:808)
at com.google.inject.internal.InjectorImpl.getJustInTimeBinding(InjectorImpl.java:285)
at com.google.inject.internal.InjectorImpl.getBindingOrThrow(InjectorImpl.java:217)
at com.google.inject.internal.InjectorImpl.getProviderOrThrow(InjectorImpl.java:1009)
at com.google.inject.internal.InjectorImpl.getProvider(InjectorImpl.java:1041)
at com.google.inject.internal.InjectorImpl.getProvider(InjectorImpl.java:1004)
at com.google.inject.internal.InjectorImpl.getInstance(InjectorImpl.java:1054)
at org.telegram.telegrambots.ApiContext.getInstance(ApiContext.java:25)
at org.telegram.telegrambots.bots.TelegramLongPollingBot.<init>(TelegramLongPollingBot.java:30)
at org.example.bOT.<init>(bOT.java:14)
at org.example.Main.main(Main.java:5)
Caused by: java.lang.ExceptionInInitializerError
at com.google.inject.internal.cglib.reflect.$FastClass$Generator.getProtectionDomain(FastClass.java:73)
at com.google.inject.internal.cglib.core.$AbstractClassGenerator.create(AbstractClassGenerator.java:206)
at com.google.inject.internal.cglib.reflect.$FastClass$Generator.create(FastClass.java:65)
at com.google.inject.internal.BytecodeGen.newFastClassForMember(BytecodeGen.java:252)
at com.google.inject.internal.BytecodeGen.newFastClassForMember(BytecodeGen.java:203)
at com.google.inject.internal.DefaultConstructionProxyFactory.create(DefaultConstructionProxyFactory.java:53)
at com.google.inject.internal.ProxyFactory.create(ProxyFactory.java:158)
at com.google.inject.internal.ConstructorInjectorStore.createConstructor(ConstructorInjectorStore.java:90)
at com.google.inject.internal.ConstructorInjectorStore.access$000(ConstructorInjectorStore.java:29)
at com.google.inject.internal.ConstructorInjectorStore$1.create(ConstructorInjectorStore.java:37)
at com.google.inject.internal.ConstructorInjectorStore$1.create(ConstructorInjectorStore.java:33)
at com.google.inject.internal.FailableCache$1.load(FailableCache.java:37)
at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3542)
at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2323)
at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2286)
at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2201)
... 20 more
Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain) throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to unnamed module @954b04f
at java.base/java.lang.reflect.AccessibleObject.throwInaccessibleObjectException(AccessibleObject.java:388)
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:364)
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:312)
at java.base/java.lang.reflect.Method.checkCanSetAccessible(Method.java:203)
at java.base/java.lang.reflect.Method.setAccessible(Method.java:197)
at com.google.inject.internal.cglib.core.$ReflectUtils$1.run(ReflectUtils.java:52)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:319)
at com.google.inject.internal.cglib.core.$ReflectUtils.<clinit>(ReflectUtils.java:42)
... 36 more