简体   繁体   English

程序无法运行扫描仪无法解决

[英]Program won't run scanner cannot be resolved

This is the code I have so far and this is only one file of multiple ones that all belong to the same program. 这是我到目前为止的代码,这只是多个文件的一个,都属于同一程序。

As soon as I want to compile and check my errors eclipse tells me that it cannot resolve the scanner and I have no idea how to fix this problem nor what it exactly means. 我要编译并检查错误时,eclipse告诉我它无法解决扫描程序,我也不知道如何解决此问题,也不知道其确切含义。

import java.util.Scanner;

public class PieShop {
    static FoodItem foodItem = new FoodItem();
    public static void main(String[] args) {
        Scanner_in.consoleLine("Enter Food item File name:");
        foodItem.foodItemFile=new File(Scanner_in.getConsole());
        foodItem.addFoodItem();
        foodItem.displayAll();
        foodItem.choices();
    }
}

Below code should work fine provided that you pass right value to scanner source 如果您将正确的值传递给扫描仪源,则下面的代码应该可以正常工作

import java.util.Scanner;

public class PieShop {
    static FoodItem foodItem = new FoodItem();
    public static void main(String[] args) {
        Scanner Scanner_in = new Scanner(source);
        Scanner_in.consoleLine("Enter Food item File name:");
        foodItem.foodItemFile=new File(Scanner_in.getConsole());
        foodItem.addFoodItem();
        foodItem.displayAll();
        foodItem.choices();
    }
}

This would be the correct way if you wan to read the input from the console: 如果您想从控制台读取输入,这将是正确的方法:

import java.util.Scanner;

public class PieShop {

    private static FoodItem foodItem = new FoodItem();

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in); // Initialize scanner
        System.out.println("Enter Food item File name:"); // Print yourtext
        foodItem.foodItemFile = new File(scanner.nextLine()); // Read from scanner
        foodItem.addFoodItem();
        foodItem.displayAll();
        foodItem.choices();
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM