I doing an assigment which require me to create a telegram bot bot

Viewed 402
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();
        }
    }

}

I put the right username and token but in here I replace it with other

I keep getting this error:

C:\Users\safwa\Documents\IntelliJ\assignment-2-safwan0908\src\main\java\my\assignment2\src\main\java\org\example\s261251Bot.java:9:8 java: cannot access java.util.concurrent.CompletableFuture class file for java.util.concurrent.CompletableFuture not found

1 Answers

I had the same problem. Make sure you use the correct or the same java version in your project and frameworks.

For more details read this article

In my case, I updated my maven version, using these properties (as described in the article):

<properties>
  <maven.compiler.source>11</maven.compiler.source>
  <maven.compiler.target>11</maven.compiler.target>
</properties>

or

<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>
Related