java - 我收到 - java.io.IOException 无法解析错误,尽管导入 IO

标签 java

// Using a do-while to process a menu selection.

public class Menu {
    public static void main(String args[]) throws java.io.IOException {
        char choice;

        do {
            System.out.println("Help on: ");
            System.out.println("  1. if");
            System.out.println("  2. switch");
            System.out.println("  3. while");
            System.out.println("  4. do-while");
            System.out.println("  5. for\n");
            System.out.println("Choose one: ");
            choice = (char) System.in.read();
        } while (choice < '1' || choice > '5');

        System.out.println("\n");

        switch (choice) {
            case '1':
                System.out.println("The if:\n");
                System.out.println("if(condition) statement;");
                System.out.println("else statement;");
            case '2':
                System.out.println("The switch:\n");
                System.out.println("switch(expression) {");
                System.out.println(" case constant:");
                System.out.println("   statement sequence");
                System.out.println("   break;");
                System.out.println("  //...");
                System.out.println("}");
                break;
            case '3':
                System.out.println("The while:\n");
                System.out.println("while(condition) statement;");
                break;
            case '4':
                System.out.println("The do-while:\n");
                System.out.println("do {");
                System.out.println("  statement;");
                System.out.println("} while (condition);");
                break;
            case '5':
                System.out.println("The for:\n");
                System.out.println("for(initialization; condition; iteration)");
                System.out.println(" statement;");
                break;
        }
    }
}

当我在 Eclipse IDE 中运行此程序时,出现此错误

Exception in thread “main” java.lang.Error: Unresolved compilation problem:
java.io.IOException cannot be resolved to a type  at Menu.main(Menu.java:3) 

我已经重建了项目,清理了几次,刷新仍然没有运气......:-(

最佳答案

您在此处提供的代码完美运行。

当您使用 Eclipse 作为 IDE 并尝试运行甚至无法编译的代码时,就会发生此错误。检查 Eclipse 中的问题 View ,并在执行应用程序之前修复编译错误。

关于java - 我收到 - java.io.IOException 无法解析错误,尽管导入 IO,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24235273/

相关文章:

java - Mule中如何动态插入json数据到数据库中

java - android.os.TransactionTooLargeException 检索已安装的应用程序

java - 如何制作日期格式以将字符串日期解析为指定的时区

java - 在 junit 5 中测试类中的 stub 私有(private)方法,PowerMock 不适用于 JUnit5

java - eclipse行号状态行贡献项是如何实现的?

java - Spring使用ref标签的本地属性引用存在于其他xml中的bean

java - 从 CLI 创建应用程序时设置 AWS IAM key

java - 对 JDK Flight Recorder 文件中的堆栈跟踪和类/方法名称进行反混淆处理

java - 使用 jGit 循环提交文件

java - 路径组件应为 '/'