F11不起作用,但ctrl + F11可以工作,Java Eclipse

时间:2018-01-27 23:21:56

标签: java eclipse keyboard-shortcuts shortcut ctrl

我在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

1 个答案:

答案 0 :(得分:0)

Ctrl + F11 是&#34; 运行&#34; F11 是&#34; 调试&#34;。
默认情况下,Eclipse Oxygen会在您运行&#34;运行&#34;它。由于您在运行代码时不会遇到任何错误,因此您可能会忽略&#34; Debug&#34;错误。
调试配置可能会发生错误 转到Run =&gt;调试配置...并删除配置。 enter image description here