为什么Eclipse会向我显示“Source not found”错误?

时间:2012-11-26 02:42:06

标签: java eclipse

这是它的样子:

enter image description here

这是我的代码:

import java.util.*;
import java.io.*;

public class ProcessSchedulingDemo {
    public static void main(String[] args) throws IOException {
        File file = new File("process-schedule.txt");
        Scanner inputFile = new Scanner(file);

        ArrayList<Process> processes = new ArrayList<Process>();

        // Skip past the first line, which is the column headers
        inputFile.nextLine();

        while (inputFile.hasNext()) {
            int processID = Integer.parseInt(inputFile.next());
            int timeUnitsRequired = Integer.parseInt(inputFile.next());
            int priority = Integer.parseInt(inputFile.next());
            int timeOfArrival = Integer.parseInt(inputFile.next());

            // Create and add to process a new process based on the information given
            Process process = new Process(processID, timeUnitsRequired, priority, timeOfArrival);
            processes.add(process);
        }

        Scanner keyboard = new Scanner(System.in);

        System.out.print("How much time does the CPU hold onto each process? ");
        int holdTime = keyboard.nextInt();

        if (holdTime <= 0) {
            while (holdTime <= 0) {
                System.out.print("Value must be greater than 0. Please input new value: ");
                holdTime = keyboard.nextInt();
            }
        }

        Heap<Process> processHeap = new Heap<Process>();

        // Holds a particular process being processed
        Process[] CPU = new Process[1];
        CPU[0] = null;

        int turn = 1;

        int timeSlices = 0;

        do {
            // Check if the list of processes has processes that should be added at the current turn
            for (int i = processes.size() - 1; i >= 0; i--) {
                if (processes.get(i).getTimeOfArrival() == turn) {
                    processHeap.add(processes.remove(i));
                }
            }

            // Print current standing of the processHeap at the beginning of the turn
            processHeap.enumerate();

            // If there currently isn't an item being processed by the CPU
            if (CPU[0] == null) {
                CPU[0] = processHeap.deleteMax();
                timeSlices = holdTime;
                System.out.println("got to cpu setting");
            }

            if (CPU[0].getTimeUnitsRequired() == 0 || timeSlices == 0) {
                if (CPU[0].getTimeUnitsRequired() > 0) {
                    processHeap.add(CPU[0]);
                }

                CPU[0] = null; 
            }
            else {
                CPU[0].setTimeUnitsRequired(CPU[0].getTimeUnitsRequired() - 1);
                timeSlices--;

                if (CPU[0].getTimeUnitsRequired() == 0 || timeSlices == 0) {
                    if (CPU[0].getTimeUnitsRequired() > 0) {
                        processHeap.add(CPU[0]);
                    }

                    CPU[0] = null;
                }
            }

            if (CPU[0] != null) {
                System.out.println("-- STATE OF CPU --");
                System.out.println("[" + CPU[0].getProcessID() + ", " + CPU[0].getTimeUnitsRequired() + ", " + CPU[0].getPriority() + "]\n");
            }

            turn++;
        } while (processes.size() != 0 && processHeap.size() != 0);
    }
}

究竟是什么造成的呢?每次我保存它弹出。哎呀。 (使用Eclipse)

2 个答案:

答案 0 :(得分:4)

Scanner是Oracle提供的Java运行时库的一部分(如果您使用的是Oracle JDK)。我认为它应该作为名为src.zip的文件包含在JDK中。您可以单击“编辑查找路径”按钮并添加此文件。它应该在您的Java JDK安装目录中。

答案 1 :(得分:1)

Eclipse调试与程序实际加载的类一起使用。

你的项目中缺少某些文件错误的东西你的项目中缺少这个错误的原因这可能由于多种原因而发生,但是看看显示此行为的类的位置(在导航窗格中查找以识别它) )。您很可能需要更改项目的构建路径以避免使用此jar并让JVM使用该项目

您可以使用此链接解决您的问题 - http://www.vogella.com/articles/Eclipse/article.html#classpath

请更新您的java和Eclipse。