You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Telegram Bot开发报错:无法访问CompletableFuture类文件

Fixing "cannot access java.util.concurrent.CompletableFuture" Error in Telegram Bot Project

It looks like you're hitting two key issues here: an incorrect project directory structure and a Java version mismatch. Let's break down how to fix both:

1. Correct Your Project Directory Structure

Looking at the error path:

C:\Users\safwa\Documents\IntelliJ\assignment-2-safwan0908\src\main\java\my\assignment2\src\main\java\org\example\s261251Bot.java

Your source files are nested inside a duplicate src/main/java directory, which confuses the compiler. Here's how to fix it:

  • Navigate to your project folder: assignment-2-safwan0908/src/main/java/my/assignment2/src/main/java/
  • Move the org folder (containing your example package and bot files) directly into the outer src/main/java folder (so it becomes assignment-2-safwan0908/src/main/java/org/example/)
  • Delete the now-empty nested directories (my/assignment2/src/main/java/)
  • Refresh your project in IntelliJ (right-click the project root > Refresh)

2. Ensure You're Using Java 8 or Higher

java.util.concurrent.CompletableFuture was introduced in Java 8. If your project is set to use an older Java version, the compiler won't find this class. Here's how to update it in IntelliJ:

  • Go to File > Project Structure (or press Ctrl+Alt+Shift+S)
  • Under Project Settings > Project:
    • Set Project SDK to Java 8 (or a newer version like Java 11/17) – if you don't have it installed, download it from Oracle or OpenJDK first
    • Set Project language level to 8 - Lambdas, type annotations etc. or higher
  • Under Project Settings > Modules:
    • Select your module, go to the Sources tab, and set Language level to match the project level (8+)
  • If you're using Maven, add these lines to your pom.xml to enforce Java 8:
    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>
    
  • If you're using Gradle, add this to your build.gradle:
    sourceCompatibility = 1.8
    targetCompatibility = 1.8
    

3. Clean and Rebuild the Project

After fixing the structure and Java version:

  • Go to Build > Clean Project
  • Then Build > Rebuild Project
  • Run your App.java again

These steps should resolve the missing CompletableFuture error and get your Telegram Bot running.

内容的提问来源于stack exchange,提问作者X unknown

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.11 08:02:14