我得到-java.io.IOException无法解决导入io时出现的错误

我得到-java.io.IOException无法解决导入io时出现的错误,java,Java,我重建了这个项目,清理了好几次,但还是没有什么好运气-(您在此处提供的代码非常有效 当您将Eclipse用作IDE并尝试运行甚至不编译的代码时,会发生此错误。请检查Eclipse中的“问题”视图,并在执行应用程序之前修复编译错误。IOException位于rt.jar中,它应该已经包含在您的jdk库中。只需确保您的项目构建路径包含您的jdk或您可以n只需在构建路径中包含rt.jar即可我在netbeans 8中运行了您的代码,效果非常好。:)听起来您的项目缺少标准库。。。右键单击项目->生成路径

我重建了这个项目,清理了好几次,但还是没有什么好运气-(

您在此处提供的代码非常有效


当您将Eclipse用作IDE并尝试运行甚至不编译的代码时,会发生此错误。请检查Eclipse中的“问题”视图,并在执行应用程序之前修复编译错误。

IOException位于rt.jar中,它应该已经包含在您的jdk库中。只需确保您的项目构建路径包含您的jdk或您可以n只需在构建路径中包含rt.jar即可

我在netbeans 8中运行了您的代码,效果非常好。:)听起来您的项目缺少标准库。。。右键单击项目->生成路径->配置生成路径…->“库”选项卡。确保列出了JRE系统库。@Jyro117您为什么相信这一点?你没有看到他在声明main方法时提供了java.io.IOException吗?java.io.IOException是自动导入的,找不到它的唯一原因是编译器找不到JRE库。谢谢朋友们的回复……你的来源在哪里?答案是什么?来源是:我在Eclipse中运行您的代码并获得预期的输出。您的eclipse设置有问题。解决这个问题。。。
// 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;
        }
    }
}
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)