java - 我做一个要求我创建一个电报机器人机器人的任务
问题描述
package org.example;
import org.telegram.telegrambots.meta.TelegramBotsApi;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
import org.telegram.telegrambots.updatesreceivers.DefaultBotSession;
public class App {
public static void main( String[] args ) {
try {
TelegramBotsApi botsApi = new TelegramBotsApi(DefaultBotSession.class);
botsApi.registerBot(new s261251Bot());
} catch (TelegramApiException e) {
e.printStackTrace();
}
}
}
package org.example;
import org.telegram.telegrambots.bots.TelegramLongPollingBot;
import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
import org.telegram.telegrambots.meta.api.objects.Update;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
public class s261251Bot extends TelegramLongPollingBot {
@Override
public String getBotUsername() {
return "username";
}
@Override
public String getBotToken() {
return "..............";
}
@Override
public void onUpdateReceived(Update update) {
SendMessage message = new SendMessage();
message.setChatId(String.valueOf((update.getMessage().getChatId())));
message.setText("hello " + update.getMessage().getFrom().getFirstName() +" " + "\nInsert your matric number." + update.getMessage().getText());
try {
execute(message);
}catch (TelegramApiException e){
e.printStackTrace();
}
}
}
我输入了正确的用户名和令牌,但在这里我将其替换为其他
我不断收到此错误:
C:\Users\safwa\Documents\IntelliJ\assignment-2-safwan0908\src\main\java\my\assignment2\src\main\java\org\example\s261251Bot.java:9:8 java: 无法访问 java。未找到 java.util.concurrent.CompletableFuture 的 util.concurrent.CompletableFuture 类文件
解决方案
我有同样的问题。确保在项目和框架中使用正确或相同的 Java 版本。
有关更多详细信息,请阅读这篇文章
就我而言,我使用这些属性(如文章中所述)更新了我的 Maven 版本:
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
或者
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>LATEST</version>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
</build>
推荐阅读
- python - Python:使用 JayDeBeApi 的 Apache Drill 错误的 JDBC 连接错误
- xero-api - 连接到 XERO API
- mysql - 如何使用首选 where 子句获取行,但也使用后备?
- c# - 将自定义设置的对象传递给嵌套类
- google-apps-script - Google Analytics API - RemarketingAudiences.insert 仅在linkedAdAccounts 为 AD_WORDS 时有效
- ios - AVPlayer 在 iOS 14.2 Beta 中无法播放
- java - 在没有观察者/听众的情况下检测变量变化?
- kotlin - 如何根据 LiveData Map 过滤 LiveData List?
- c# - Entity Framework Core - 如果直接在数据库中完成 CRUD 操作,跟踪记录会发生什么情况?
- html - 如何在html中垂直给按钮之间留出空间?