我在Eclipse中遇到一个我要运行的特定程序的问题。我添加了一个外部库xchart,该库基本上用于在Java中创建图表。按ctrl + F11可以正常运行该程序,但是按F11可以给我FileNotFoundException,即使我非常确定路径是否正确。这是我放置在名为HistogramText.txt的程序包中的文本文件。

package mainP;

import java.awt.Color;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.*;
import org.knowm.xchart.CategoryChart;
import org.knowm.xchart.CategoryChartBuilder;
import org.knowm.xchart.SwingWrapper;
import org.knowm.xchart.demo.charts.ExampleChart;
import org.knowm.xchart.style.Styler.ChartTheme;
import org.knowm.xchart.style.Styler.LegendPosition;

public class HistogramBarChart implements ExampleChart<CategoryChart> {

public static void main(String[] args) {
try {
    ExampleChart<CategoryChart> barChart = new HistogramBarChart();
    CategoryChart bchart = barChart.getChart();
    new SwingWrapper<CategoryChart>(bchart).displayChart();

}catch(Exception e) {
System.out.println("");
}
    }

private int[] Temp() throws FileNotFoundException {

    int num = 0;
    int[] arr = new int[12];
    try {
    File file = new File("src/mainP/HistogramText.txt");

        Scanner fScan = new Scanner(file);
        while (fScan.hasNext()) {
            num = fScan.nextInt();
            arr[11]++;
            if (num > 100) {
                arr[10]++;
            }

            if (num >= 1 && num <= 10) { // Adding all the values to array positions 0-9
                arr[0]++;
            }

            if (num >= 11 && num <= 20) {
                arr[1]++;
            }

            if (num >= 21 && num <= 30) {
                arr[2]++;
            }

            if (num >= 31 && num <= 40) {
                arr[3]++;
            }

            if (num >= 41 && num <= 50) {
                arr[4]++;
            }

            if (num >= 51 && num <= 60) {
                arr[5]++;
            }

            if (num >= 61 && num <= 70) {
                arr[6]++;
            }

            if (num >= 71 && num <= 80) {
                arr[7]++;
            }

            if (num >= 81 && num <= 90) {
                arr[8]++;
            }

            if (num >= 91 && num <= 100) {
                arr[9]++;
            }
        }

        fScan.close();
    } catch (FileNotFoundException e) {
        System.out.println("Lmao");
    }

    return arr;
}

public CategoryChart getChart() {
    int[] arr;
        try {
            arr = Temp();


    // Create Chart
    CategoryChart chart = new CategoryChartBuilder().width(800).height(600).title("Histogram Bar Chart")
            .xAxisTitle("Range").yAxisTitle("Numbers").theme(ChartTheme.GGPlot2).build();

    // Customize Chart
    chart.getStyler().setLegendPosition(LegendPosition.InsideNW);
    chart.getStyler().setHasAnnotations(true);
    chart.getStyler().setChartFontColor(Color.black);

    // Series
    chart.addSeries("Numbers in HistrogramText",
            Arrays.asList(new String[] { "1 - 10", "11 - 20", "21 - 30", "31 - 40", "41 - 50", "51 - 60", "61 - 70",
                    "71 - 80", "81 - 90", "91 - 100", "100+", "All numbers" }),
            Arrays.asList(new Integer[] { arr[0], arr[1], arr[2], arr[3], arr[4], arr[5], arr[6], arr[7], arr[8],
                    arr[9], arr[10], arr[11] }));

    return chart;
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            return null;
        }

}

}


这几乎是代码。外部库为xchart-3.5.0.jar和xchart-demo-3.5.0.jar

Thread [main] (Suspended (exception FileNotFoundException))
FileInputStream.open0(String) line: not available [native method]
FileInputStream.open(String) line: not available
FileInputStream.<init>(File) line: not available
Toolkit$1.run() line: not available
Toolkit$1.run() line: not available
AccessController.doPrivileged(PrivilegedAction<T>) line: not available
[native method]
Toolkit.initAssistiveTechnologies() line: not available
Toolkit.<clinit>() line: not available
Font.<clinit>() line: not available
AbstractBaseTheme.<clinit>() line: 39
Styler$ChartTheme.newInstance(Styler$ChartTheme) line: 51
CategoryChart.<init>(int, int, Styler$ChartTheme) line: 79
CategoryChart.<init>(CategoryChartBuilder) line: 89
CategoryChartBuilder.build() line: 53
HistogramBarChart.getChart() line: 101
HistogramBarChart.getChart() line: 1
HistogramBarChart.main(String[]) line: 20


这是我使用F11运行时遇到的错误。我是编程新手,所以可以提供一些帮助:D

最佳答案

Ctrl + F11为“运行”,F11为“调试”。
默认情况下,“运行”时,Eclipse Oxygen会自动构建您的项目。由于在运行代码时不会遇到任何错误,因此可以忽略“调试”错误。
该错误可能是由您的调试配置引起的。
转到运行=>调试配置...,然后删除配置。
java - F11不起作用,但ctrl &#43; F11起作用,Java Eclipse-LMLPHP

关于java - F11不起作用,但ctrl + F11起作用,Java Eclipse,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48481587/

10-10 22:58