简体   繁体   English

为什么Eclipse会显示“找不到源”错误?

[英]Why does Eclipse show me a “Source not found” error?

Here's what it looks like: 看起来是这样的:

在此处输入图片说明

And here's my code: 这是我的代码:

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);
    }
}

What on earth is causing it? 到底是什么引起的? EVERY time I save it pops up. 每次我保存时都会弹出。 Argh. 哎呀。 (Using Eclipse) (使用Eclipse)

Scanner is part of the Java run time libraries, provided by Oracle (if you're using the Oracle JDK). 扫描程序是Oracle提供的Java运行时库的一部分(如果使用的是Oracle JDK)。 I think it should be included with the JDK as a file called src.zip. 我认为它应该作为一个名为src.zip的文件包含在JDK中。 You can click the Edit Lookup Path button and add this file. 您可以单击“编辑查找路径”按钮并添加此文件。 It should be in your Java JDK install directory. 它应该在您的Java JDK安装目录中。

Eclipse debugging works with the class actually loaded by the program. Eclipse调试适用于程序实际加载的类。

Something you installed wrong to some file is missing in your project that why you get this errorThis can happen for several reasons but have a look at the location where the classes showing this behaviour is found (look in the navigation pane to identify it). 您的项目中缺少某些文件安装错误,这是您收到此错误的原因。这可能由于多种原因而发生,但请查看发现该行为的类所在的位置(在导航窗格中进行识别)。 You will most likely need to change the build path of the project to avoid using this jar and have the JVM use the project instead 您很可能需要更改项目的构建路径,以避免使用此jar,而让JVM使用项目

you can use this link to solved your problem - http://www.vogella.com/articles/Eclipse/article.html#classpath 您可以使用此链接解决问题-http: //www.vogella.com/articles/Eclipse/article.html#classpath

Please update your java and Eclipse. 请更新您的Java和Eclipse。

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

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