简体   繁体   English

F11不起作用,但ctrl + F11起作用,Java Eclipse

[英]F11 doesn't work but ctrl + F11 works, Java Eclipse

I have a problem in Eclipse with a specific program I'm trying to run. 我在Eclipse中遇到一个我要运行的特定程序的问题。 I added an external library xchart which is basically for creating charts in java. 我添加了一个外部库xchart,该库基本上用于在Java中创建图表。 Pressing ctrl+F11 runs the program normally but pressing F11 gives me FileNotFoundException even tho I am pretty sure the path is correct. 按ctrl + F11可以正常运行该程序,但是按F11可以给我FileNotFoundException,即使我很确定路径是正确的。 It is I text file I have put inside the package called HistogramText.txt. 这是我放置在名为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;
        }

}

}

This is pretty much the code. 这几乎是代码。 The external Libraries are xchart-3.5.0.jar and xchart-demo-3.5.0.jar 外部库为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   

And this is the error I get when I run with F11. 这是我使用F11运行时遇到的错误。 I'm quite new at programming so some help would be appreciated :D 我是编程新手,所以可以提供一些帮助:D

Ctrl+F11 is " Run " and F11 is " Debug ". Ctrl + F11为“ 运行 ”, F11为“ 调试 ”。
Eclipse Oxygen, by default, automatically builds your project when you "Run" it. 默认情况下,“运行”时,Eclipse Oxygen会自动构建您的项目。 Since you don't face any errors while running your code, you may ignore the "Debug" error. 由于在运行代码时不会遇到任何错误,因此您可以忽略“调试”错误。
The error may occur from your debug configuration. 该错误可能是由您的调试配置引起的。
Go to Run=>Debug configurations... and remove configurations. 转到运行=>调试配置...,然后删除配置。 在此处输入图片说明

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

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